diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-06-11 06:20:39 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-06-11 06:20:39 +0000 |
commit | 61b529f466d959215ea5b5bc95cb4f85d203c35d (patch) | |
tree | 4dadeeefce0bd555bb00b235f42592f542e31d03 /clang/lib/Sema/SemaDecl.cpp | |
parent | d2c8970a9ac91d51e4f5d8b71ee9b1b57a5690ec (diff) | |
download | bcm5719-llvm-61b529f466d959215ea5b5bc95cb4f85d203c35d.tar.gz bcm5719-llvm-61b529f466d959215ea5b5bc95cb4f85d203c35d.zip |
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.
llvm-svn: 52209
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 2d6422fb007..0bab523043c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -230,28 +230,31 @@ TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { // 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; |