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>.

llvm-svn: 115259
This commit is contained in:
Douglas Gregor 2010-10-01 01:03:07 +00:00
parent 220d971ace
commit eb114da506
4 changed files with 11 additions and 2 deletions

View 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);

View File

@ -2,3 +2,4 @@ void f() __attribute__((unavailable));
void g();
#define g() f()
#define h() f()
#define x x

View File

@ -2,3 +2,4 @@
#undef g
#undef h
#define h() g()
int x;

View 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;
}