]> granicus.if.org Git - clang/commitdiff
When an identifier that has a macro definition in the original PCH
authorDouglas Gregor <dgregor@apple.com>
Fri, 1 Oct 2010 01:03:07 +0000 (01:03 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 1 Oct 2010 01:03:07 +0000 (01:03 +0000)
file is somehow changed in a chained PCH file, make sure that we write
out the macro definition. Fixes part of <rdar://problem/8499034>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115259 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTWriter.cpp
test/PCH/Inputs/chain-macro-override1.h
test/PCH/Inputs/chain-macro-override2.h
test/PCH/chain-macro-override.c

index 3f537d21ab574fb5bc3b4ecc9552edc466454aa1..f5f96ecd24e8081fb098af855e888f5134e5c617 100644 (file)
@@ -1276,7 +1276,13 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
     // Don't emit builtin macros like __LINE__ to the AST file unless they have
     // been redefined by the header (in which case they are not isBuiltinMacro).
     // Also skip macros from a AST file if we're chaining.
-    if (MI->isBuiltinMacro() || (Chain && MI->isFromAST()))
+
+    // FIXME: There is a (probably minor) optimization we could do here, if
+    // the macro comes from the original PCH but the identifier comes from a
+    // chained PCH, by storing the offset into the original PCH rather than
+    // writing the macro definition a second time.
+    if (MI->isBuiltinMacro() || 
+        (Chain && I->first->isFromAST() && MI->isFromAST()))
       continue;
 
     AddIdentifierRef(I->first, Record);
index 4f9321de93b17c4fd26544573d5cca27bacf9cfb..d956396f9160f620ec86f17daedef3488383c5de 100644 (file)
@@ -2,3 +2,4 @@ void f() __attribute__((unavailable));
 void g();
 #define g() f()
 #define h() f()
+#define x x
index f279e2ad48c04f625ad7fa5742ea93543e934490..e4bff77294fd9613584cfa65b70afb28e6a93399 100644 (file)
@@ -2,3 +2,4 @@
 #undef g
 #undef h
 #define h() g()
+int x;
index 14478af35f199964fc09fd8eb4e018c7f86ec3b8..449ed8c7a0c439a2871d159fc54463e218a88b4f 100644 (file)
@@ -6,8 +6,9 @@
 // RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro-override2.h -include-pch %t1 -chained-pch
 // RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s
 
-void foo() {
+int foo() {
   f();
   g();
   h();
+  return x;
 }