]> granicus.if.org Git - clang/commitdiff
Fix null pointer dereference if we redeclare an unprototyped function. Patch by
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 25 Jun 2013 20:34:17 +0000 (20:34 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 25 Jun 2013 20:34:17 +0000 (20:34 +0000)
WenHan Gu!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184875 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/vfprintf-valid-redecl.c

index 43db2962a7e978486e2e24048e3618c7ad51a0df..a5092d5a389d9a2d2b723661df0f548e82fb4999 100644 (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");
+      }
     }
   }
 
index 5c5ce8d12b002d7735c7fbb2f891d492b018825b..5c78874feb6c36c17eb1e5c042c5c4a8283622ff 100644 (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();