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

Richard Smith richard-llvm at metafoo.co.uk
Tue Jun 25 13:34:17 PDT 2013


Author: rsmith
Date: Tue Jun 25 15:34:17 2013
New Revision: 184875

URL: http://llvm.org/viewvc/llvm-project?rev=184875&view=rev
Log:
Fix null pointer dereference if we redeclare an unprototyped function. Patch by
WenHan Gu!

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/vfprintf-valid-redecl.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=184875&r1=184874&r2=184875&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jun 25 15:34:17 2013
@@ -8732,17 +8732,19 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop
   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");
+      }
     }
   }
 

Modified: cfe/trunk/test/Sema/vfprintf-valid-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vfprintf-valid-redecl.c?rev=184875&r1=184874&r2=184875&view=diff
==============================================================================
--- cfe/trunk/test/Sema/vfprintf-valid-redecl.c (original)
+++ cfe/trunk/test/Sema/vfprintf-valid-redecl.c Tue Jun 25 15:34:17 2013
@@ -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();





More information about the cfe-commits mailing list