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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52209 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 2d6422f..0bab523 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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();
-  const FileEntry *OldDeclFile = SrcMgr.getFileEntryForLoc(Old->getLocation());
-  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; ...
+  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());
+  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;