<div dir="ltr">On Tue, Jun 25, 2013 at 1:34 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Tue Jun 25 15:34:17 2013<br>
New Revision: 184875<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=184875&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=184875&view=rev</a><br>
Log:<br>
Fix null pointer dereference if we redeclare an unprototyped function. Patch by<br>
WenHan Gu!<br>
<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaDecl.cpp<br>
    cfe/trunk/test/Sema/vfprintf-valid-redecl.c<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=184875&r1=184874&r2=184875&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=184875&r1=184874&r2=184875&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jun 25 15:34:17 2013<br>
@@ -8732,17 +8732,19 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop<br>
   const FunctionDecl *PossibleZeroParamPrototype = 0;<br>
   if (ShouldWarnAboutMissingPrototype(FD, PossibleZeroParamPrototype)) {<br>
     Diag(FD->getLocation(), diag::warn_missing_prototype) << FD;<br>
-<br>
+<br>
     if (PossibleZeroParamPrototype) {<br>
-      // We found a declaration that is not a prototype,<br>
+      // We found a declaration that is not a prototype,<br>
       // but that could be a zero-parameter prototype<br>
-      TypeSourceInfo* TI = PossibleZeroParamPrototype->getTypeSourceInfo();<br>
-      TypeLoc TL = TI->getTypeLoc();<br>
-      if (FunctionNoProtoTypeLoc FTL = TL.getAs<FunctionNoProtoTypeLoc>())<br>
-        Diag(PossibleZeroParamPrototype->getLocation(),<br>
-             diag::note_declaration_not_a_prototype)<br>
-          << PossibleZeroParamPrototype<br>
-          << FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");<br>
+      if (TypeSourceInfo *TI =<br>
+              PossibleZeroParamPrototype->getTypeSourceInfo()) {<br>
+        TypeLoc TL = TI->getTypeLoc();<br>
+        if (FunctionNoProtoTypeLoc FTL = TL.getAs<FunctionNoProtoTypeLoc>())<br>
+          Diag(PossibleZeroParamPrototype->getLocation(),<br>
+               diag::note_declaration_not_a_prototype)<br>
+            << PossibleZeroParamPrototype<br>
+            << FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");<br>
+      }<br>
     }<br>
   }<br>
<br>
<br>
Modified: cfe/trunk/test/Sema/vfprintf-valid-redecl.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vfprintf-valid-redecl.c?rev=184875&r1=184874&r2=184875&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vfprintf-valid-redecl.c?rev=184875&r1=184874&r2=184875&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/Sema/vfprintf-valid-redecl.c (original)<br>
+++ cfe/trunk/test/Sema/vfprintf-valid-redecl.c Tue Jun 25 15:34:17 2013<br>
@@ -1,7 +1,13 @@<br>
 // RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify<br>
 // expected-no-diagnostics<br>
-// PR4290<br>
<br>
+// PR16344<br>
+// Clang has defined 'vfprint' in builtin list. If the following line occurs before any other<br>
+// `vfprintf' in this file, and we getPreviousDecl()->getTypeSourceInfo() on it, then we will<br>
+// get a null pointer since the one in builtin list doesn't has valid TypeSourceInfo.<br>
+int vfprintf(void) { return 0; }<br>
+<br>
+// PR4290<br>
 // The following declaration is compatible with vfprintf, so we shouldn't<br>
 // warn.<br>
 int vfprintf();<br><br></blockquote><div>This testcase isn't testing what it was originally supposed to test.</div><div><br></div><div>-Eli </div></div></div></div>