From: Douglas Gregor Date: Fri, 1 Oct 2010 01:03:07 +0000 (+0000) Subject: When an identifier that has a macro definition in the original PCH X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee9b0ba29094eb177a285e726ab96e979e5b9c61;p=clang 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 . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115259 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 3f537d21ab..f5f96ecd24 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -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); diff --git a/test/PCH/Inputs/chain-macro-override1.h b/test/PCH/Inputs/chain-macro-override1.h index 4f9321de93..d956396f91 100644 --- a/test/PCH/Inputs/chain-macro-override1.h +++ b/test/PCH/Inputs/chain-macro-override1.h @@ -2,3 +2,4 @@ void f() __attribute__((unavailable)); void g(); #define g() f() #define h() f() +#define x x diff --git a/test/PCH/Inputs/chain-macro-override2.h b/test/PCH/Inputs/chain-macro-override2.h index f279e2ad48..e4bff77294 100644 --- a/test/PCH/Inputs/chain-macro-override2.h +++ b/test/PCH/Inputs/chain-macro-override2.h @@ -2,3 +2,4 @@ #undef g #undef h #define h() g() +int x; diff --git a/test/PCH/chain-macro-override.c b/test/PCH/chain-macro-override.c index 14478af35f..449ed8c7a0 100644 --- a/test/PCH/chain-macro-override.c +++ b/test/PCH/chain-macro-override.c @@ -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; }