summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-01-30 23:46:05 +0000
committerSteve Naroff <snaroff@apple.com>2008-01-30 23:46:05 +0000
commite101f9548eef234f15ad6b89d0ae9d78f9dd12c2 (patch)
treed12a3702b996cac1b5a89088fb21d21f345299f7
parent2531fce319dd676c29da3877048038137995cef4 (diff)
downloadbcm5719-llvm-e101f9548eef234f15ad6b89d0ae9d78f9dd12c2.tar.gz
bcm5719-llvm-e101f9548eef234f15ad6b89d0ae9d78f9dd12c2.zip
Hack Sema::MergeTypeDefDecl() to silently ignore duplicate typedef's in system headers files.
A bizarre, non-standard hook that many compilers appear to implement (sigh:-). llvm-svn: 46583
-rw-r--r--clang/Sema/SemaDecl.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index aaa1c820218..f45b3398194 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -21,6 +21,10 @@
#include "clang/Parse/Scope.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/SourceManager.h"
+// FIXME: layering (ideally, Sema shouldn't be dependent on Lex API's)
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/HeaderSearch.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/DenseSet.h"
@@ -210,6 +214,22 @@ TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *OldD) {
// FIXME: Verify the underlying types are equivalent!
if (getLangOptions().ObjC1 && isBuiltinObjCType(New))
return Old;
+
+ // 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);
+
+ if (OldDirType == DirectoryLookup::ExternCSystemHeaderDir ||
+ NewDirType == DirectoryLookup::ExternCSystemHeaderDir)
+ return New;
// TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
// TODO: This is totally simplistic. It should handle merging functions
OpenPOWER on IntegriCloud