Fix null pointer dereference if we redeclare an unprototyped function. Patch by

WenHan Gu!

llvm-svn: 184875
This commit is contained in:
Richard Smith 2013-06-25 20:34:17 +00:00
parent 3d3295daab
commit ef87be3a62
2 changed files with 18 additions and 10 deletions

View File

@ -8732,17 +8732,19 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
const FunctionDecl *PossibleZeroParamPrototype = 0;
if (ShouldWarnAboutMissingPrototype(FD, PossibleZeroParamPrototype)) {
Diag(FD->getLocation(), diag::warn_missing_prototype) << FD;
if (PossibleZeroParamPrototype) {
// We found a declaration that is not a prototype,
// We found a declaration that is not a prototype,
// but that could be a zero-parameter prototype
TypeSourceInfo* TI = PossibleZeroParamPrototype->getTypeSourceInfo();
TypeLoc TL = TI->getTypeLoc();
if (FunctionNoProtoTypeLoc FTL = TL.getAs<FunctionNoProtoTypeLoc>())
Diag(PossibleZeroParamPrototype->getLocation(),
diag::note_declaration_not_a_prototype)
<< PossibleZeroParamPrototype
<< FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");
if (TypeSourceInfo *TI =
PossibleZeroParamPrototype->getTypeSourceInfo()) {
TypeLoc TL = TI->getTypeLoc();
if (FunctionNoProtoTypeLoc FTL = TL.getAs<FunctionNoProtoTypeLoc>())
Diag(PossibleZeroParamPrototype->getLocation(),
diag::note_declaration_not_a_prototype)
<< PossibleZeroParamPrototype
<< FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");
}
}
}

View File

@ -1,7 +1,13 @@
// RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify
// expected-no-diagnostics
// PR4290
// PR16344
// Clang has defined 'vfprint' in builtin list. If the following line occurs before any other
// `vfprintf' in this file, and we getPreviousDecl()->getTypeSourceInfo() on it, then we will
// get a null pointer since the one in builtin list doesn't has valid TypeSourceInfo.
int vfprintf(void) { return 0; }
// PR4290
// The following declaration is compatible with vfprintf, so we shouldn't
// warn.
int vfprintf();