[cfe-commits] r115259 - in /cfe/trunk: lib/Serialization/ASTWriter.cpp test/PCH/Inputs/chain-macro-override1.h test/PCH/Inputs/chain-macro-override2.h test/PCH/chain-macro-override.c

Douglas Gregor dgregor at apple.com
Thu Sep 30 18:03:07 PDT 2010


Author: dgregor
Date: Thu Sep 30 20:03:07 2010
New Revision: 115259

URL: http://llvm.org/viewvc/llvm-project?rev=115259&view=rev
Log:
When an identifier that has a macro definition in the original PCH
file is somehow changed in a chained PCH file, make sure that we write
out the macro definition. Fixes part of <rdar://problem/8499034>.

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

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=115259&r1=115258&r2=115259&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Sep 30 20:03:07 2010
@@ -1276,7 +1276,13 @@
     // 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);

Modified: cfe/trunk/test/PCH/Inputs/chain-macro-override1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-macro-override1.h?rev=115259&r1=115258&r2=115259&view=diff
==============================================================================
--- cfe/trunk/test/PCH/Inputs/chain-macro-override1.h (original)
+++ cfe/trunk/test/PCH/Inputs/chain-macro-override1.h Thu Sep 30 20:03:07 2010
@@ -2,3 +2,4 @@
 void g();
 #define g() f()
 #define h() f()
+#define x x

Modified: cfe/trunk/test/PCH/Inputs/chain-macro-override2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-macro-override2.h?rev=115259&r1=115258&r2=115259&view=diff
==============================================================================
--- cfe/trunk/test/PCH/Inputs/chain-macro-override2.h (original)
+++ cfe/trunk/test/PCH/Inputs/chain-macro-override2.h Thu Sep 30 20:03:07 2010
@@ -2,3 +2,4 @@
 #undef g
 #undef h
 #define h() g()
+int x;

Modified: cfe/trunk/test/PCH/chain-macro-override.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-macro-override.c?rev=115259&r1=115258&r2=115259&view=diff
==============================================================================
--- cfe/trunk/test/PCH/chain-macro-override.c (original)
+++ cfe/trunk/test/PCH/chain-macro-override.c Thu Sep 30 20:03:07 2010
@@ -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;
 }





More information about the cfe-commits mailing list