From: Sebastian Redl Date: Fri, 30 Jul 2010 17:25:10 +0000 (+0000) Subject: Correctly deal with using names for both functions and structs in chained PCH. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1450ef99896d66ba67e2ddd2798a29be1bf560b8;p=clang Correctly deal with using names for both functions and structs in chained PCH. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109871 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index b09526e097..62df1a7c2c 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -139,6 +139,9 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, /// AddDecl - Link the decl to its shadowed decl chain. void IdentifierResolver::AddDecl(NamedDecl *D) { DeclarationName Name = D->getDeclName(); + if (IdentifierInfo *II = Name.getAsIdentifierInfo()) + II->setIsFromPCH(false); + void *Ptr = Name.getFETokenInfo(); if (!Ptr) { @@ -164,6 +167,9 @@ void IdentifierResolver::AddDecl(NamedDecl *D) { void IdentifierResolver::RemoveDecl(NamedDecl *D) { assert(D && "null param passed"); DeclarationName Name = D->getDeclName(); + if (IdentifierInfo *II = Name.getAsIdentifierInfo()) + II->setIsFromPCH(false); + void *Ptr = Name.getFETokenInfo(); assert(Ptr && "Didn't find this decl on its identifier's chain!"); @@ -182,6 +188,9 @@ bool IdentifierResolver::ReplaceDecl(NamedDecl *Old, NamedDecl *New) { "Cannot replace a decl with another decl of a different name"); DeclarationName Name = Old->getDeclName(); + if (IdentifierInfo *II = Name.getAsIdentifierInfo()) + II->setIsFromPCH(false); + void *Ptr = Name.getFETokenInfo(); if (!Ptr) @@ -218,6 +227,7 @@ IdentifierResolver::begin(DeclarationName Name) { void IdentifierResolver::AddDeclToIdentifierChain(IdentifierInfo *II, NamedDecl *D) { + II->setIsFromPCH(false); void *Ptr = II->getFETokenInfo(); if (!Ptr) { diff --git a/test/PCH/Inputs/chain-decls1.h b/test/PCH/Inputs/chain-decls1.h new file mode 100644 index 0000000000..79586ce42a --- /dev/null +++ b/test/PCH/Inputs/chain-decls1.h @@ -0,0 +1,4 @@ +void f(); + +struct one {}; +void two(); diff --git a/test/PCH/Inputs/chain-decls2.h b/test/PCH/Inputs/chain-decls2.h new file mode 100644 index 0000000000..1826da9415 --- /dev/null +++ b/test/PCH/Inputs/chain-decls2.h @@ -0,0 +1,5 @@ +void g(); + +struct two {}; +void one(); +struct three {}; // for verification diff --git a/test/PCH/Inputs/chain-function1.h b/test/PCH/Inputs/chain-function1.h deleted file mode 100644 index 789447c027..0000000000 --- a/test/PCH/Inputs/chain-function1.h +++ /dev/null @@ -1 +0,0 @@ -void f(); diff --git a/test/PCH/Inputs/chain-function2.h b/test/PCH/Inputs/chain-function2.h deleted file mode 100644 index e8fc9651ed..0000000000 --- a/test/PCH/Inputs/chain-function2.h +++ /dev/null @@ -1 +0,0 @@ -void g(); diff --git a/test/PCH/chain-decls.c b/test/PCH/chain-decls.c new file mode 100644 index 0000000000..f790a29254 --- /dev/null +++ b/test/PCH/chain-decls.c @@ -0,0 +1,22 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/Inputs/chain-decls1.h -include %S/Inputs/chain-decls2.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-decls1.h +// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-decls2.h -include-pch %t1 -chained-pch +// RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s +// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s + +// CHECK: void f(); +// CHECK: void g(); + +void h() { + f(); + g(); + + struct one x; + one(); + struct two y; + two(); + struct three z; +} diff --git a/test/PCH/chain-function.c b/test/PCH/chain-function.c deleted file mode 100644 index 0d766fbfc3..0000000000 --- a/test/PCH/chain-function.c +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-function1.h -// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-function2.h -include-pch %t1 -chained-pch -// RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s -// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s - -// CHECK: void f(); -// CHECK: void g(); - -void h() { - f(); - g(); -}