[cfe-commits] r52209 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/typedef-redef.c

Eli Friedman eli.friedman at gmail.com
Tue Jun 10 23:20:39 PDT 2008


Author: efriedma
Date: Wed Jun 11 01:20:39 2008
New Revision: 52209

URL: http://llvm.org/viewvc/llvm-project?rev=52209&view=rev
Log:
Don't crash if we can't find FileEntry info for a typedef, since one 
isn't guaranteed to exist. This fixes a crash with conflicting typedefs
coming from stdin.

This also fixes the crash in PR2406, but doesn't completely fix the 
issue; it appears there's something strange about the physical location 
for the definition of int64_t in stdlib.h.


Added:
    cfe/trunk/test/Sema/typedef-redef.c
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=52209&r1=52208&r2=52209&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jun 11 01:20:39 2008
@@ -230,28 +230,31 @@
   // FIXME: Verify the underlying types are equivalent!
   if (getLangOptions().ObjC1 && isBuiltinObjCType(New))
     return Old;
-  
+
+  if (getLangOptions().Microsoft) return New;
+
   // Redeclaration of a type is a constraint violation (6.7.2.3p1).
   // Apparently GCC, Intel, and Sun all silently ignore the redeclaration if
   // *either* declaration is in a system header. The code below implements
   // this adhoc compatibility rule. FIXME: The following code will not
   // work properly when compiling ".i" files (containing preprocessed output).
   SourceManager &SrcMgr = Context.getSourceManager();
+  HeaderSearch &HdrInfo = PP.getHeaderSearchInfo();
   const FileEntry *OldDeclFile = SrcMgr.getFileEntryForLoc(Old->getLocation());
+  if (OldDeclFile) {
+    DirectoryLookup::DirType OldDirType = HdrInfo.getFileDirFlavor(OldDeclFile);
+    // Allow reclarations in both SystemHeaderDir and ExternCSystemHeaderDir.
+    if (OldDirType != DirectoryLookup::NormalHeaderDir)
+      return New;
+  }
   const FileEntry *NewDeclFile = SrcMgr.getFileEntryForLoc(New->getLocation());
-  HeaderSearch &HdrInfo = PP.getHeaderSearchInfo();
-  DirectoryLookup::DirType OldDirType = HdrInfo.getFileDirFlavor(OldDeclFile);
-  DirectoryLookup::DirType NewDirType = HdrInfo.getFileDirFlavor(NewDeclFile);
-  
-  // Allow reclarations in both SystemHeaderDir and ExternCSystemHeaderDir.
-  if ((OldDirType != DirectoryLookup::NormalHeaderDir ||
-       NewDirType != DirectoryLookup::NormalHeaderDir) ||
-      getLangOptions().Microsoft)
-    return New;
-      
-  // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
-  // TODO: This is totally simplistic.  It should handle merging functions
-  // together etc, merging extern int X; int X; ...
+  if (NewDeclFile) {
+    DirectoryLookup::DirType NewDirType = HdrInfo.getFileDirFlavor(NewDeclFile);
+    // Allow reclarations in both SystemHeaderDir and ExternCSystemHeaderDir.
+    if (NewDirType != DirectoryLookup::NormalHeaderDir)
+      return New;
+  }
+
   Diag(New->getLocation(), diag::err_redefinition, New->getName());
   Diag(Old->getLocation(), diag::err_previous_definition);
   return New;

Added: cfe/trunk/test/Sema/typedef-redef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typedef-redef.c?rev=52209&view=auto

==============================================================================
--- cfe/trunk/test/Sema/typedef-redef.c (added)
+++ cfe/trunk/test/Sema/typedef-redef.c Wed Jun 11 01:20:39 2008
@@ -0,0 +1,4 @@
+// RUN: clang < %s -fsyntax-only -verify
+
+#include <stddef.h>
+typedef unsigned long size_t;





More information about the cfe-commits mailing list