summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-08-18 20:39:29 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-08-18 20:39:29 +0000
commit293534b1a50f7489f6d6e2c24aeccc8e7db88c05 (patch)
treedc32e59f7a8de096b84d1202bbc73093e1747083
parent35b0eaf23d5fe90ad9a04f76488c212cb6f31210 (diff)
downloadbcm5719-llvm-293534b1a50f7489f6d6e2c24aeccc8e7db88c05.tar.gz
bcm5719-llvm-293534b1a50f7489f6d6e2c24aeccc8e7db88c05.zip
Initialize the AST consumer as soon as we have both an ASTConsumer and an
ASTContext. Fixes some cases where we could previously initialize the AST consumer more than once. llvm-svn: 245346
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp7
-rw-r--r--clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp5
-rw-r--r--clang/lib/Frontend/ASTMerge.cpp1
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp23
-rw-r--r--clang/lib/Sema/Sema.cpp4
-rw-r--r--clang/test/Index/index-pch-with-module.m2
-rw-r--r--clang/test/Index/skip-parsed-bodies/compile_commands.json5
7 files changed, 23 insertions, 24 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 5f199bd3a4c..062c7be47b7 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -82,11 +82,8 @@ namespace clang {
}
void Initialize(ASTContext &Ctx) override {
- if (Context) {
- assert(Context == &Ctx);
- return;
- }
-
+ assert(!Context && "initialized multiple times");
+
Context = &Ctx;
if (llvm::TimePassesIsEnabled)
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
index 526c0c71de5..3611d9aa86f 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -71,10 +71,7 @@ public:
virtual ~PCHContainerGenerator() {}
void Initialize(ASTContext &Context) override {
- if (Ctx) {
- assert(Ctx == &Context);
- return;
- }
+ assert(!Ctx && "initialized multiple times");
Ctx = &Context;
VMContext.reset(new llvm::LLVMContext());
diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp
index 762c7a5da5e..b499fa2b0e6 100644
--- a/clang/lib/Frontend/ASTMerge.cpp
+++ b/clang/lib/Frontend/ASTMerge.cpp
@@ -59,7 +59,6 @@ void ASTMergeAction::ExecuteAction() {
/*MinimalImport=*/false);
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
- CI.getASTConsumer().Initialize(CI.getASTContext());
for (auto *D : TU->decls()) {
// Don't re-import __va_list_tag, __builtin_va_list.
if (const auto *ND = dyn_cast<NamedDecl>(D))
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 5079353226c..dfd71afca48 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -96,7 +96,12 @@ void CompilerInstance::setSourceManager(SourceManager *Value) {
void CompilerInstance::setPreprocessor(Preprocessor *Value) { PP = Value; }
-void CompilerInstance::setASTContext(ASTContext *Value) { Context = Value; }
+void CompilerInstance::setASTContext(ASTContext *Value) {
+ Context = Value;
+
+ if (Context && Consumer)
+ getASTConsumer().Initialize(getASTContext());
+}
void CompilerInstance::setSema(Sema *S) {
TheSema.reset(S);
@@ -104,6 +109,9 @@ void CompilerInstance::setSema(Sema *S) {
void CompilerInstance::setASTConsumer(std::unique_ptr<ASTConsumer> Value) {
Consumer = std::move(Value);
+
+ if (Context && Consumer)
+ getASTConsumer().Initialize(getASTContext());
}
void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) {
@@ -385,10 +393,11 @@ std::string CompilerInstance::getSpecificModuleCachePath() {
void CompilerInstance::createASTContext() {
Preprocessor &PP = getPreprocessor();
- Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
- PP.getIdentifierTable(), PP.getSelectorTable(),
- PP.getBuiltinInfo());
+ auto *Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
+ PP.getIdentifierTable(), PP.getSelectorTable(),
+ PP.getBuiltinInfo());
Context->InitBuiltinTypes(getTarget());
+ setASTContext(Context);
}
// ExternalASTSource
@@ -1249,7 +1258,7 @@ void CompilerInstance::createModuleManager() {
ReadTimer = llvm::make_unique<llvm::Timer>("Reading modules",
*FrontendTimerGroup);
ModuleManager = new ASTReader(
- getPreprocessor(), *Context, getPCHContainerReader(),
+ getPreprocessor(), getASTContext(), getPCHContainerReader(),
Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation,
/*AllowASTWithCompilerErrors=*/false,
/*AllowConfigurationMismatch=*/false,
@@ -1265,10 +1274,8 @@ void CompilerInstance::createModuleManager() {
getASTContext().setExternalSource(ModuleManager);
if (hasSema())
ModuleManager->InitializeSema(getSema());
- if (hasASTConsumer()) {
- getASTConsumer().Initialize(getASTContext());
+ if (hasASTConsumer())
ModuleManager->StartTranslationUnit(&getASTConsumer());
- }
if (TheDependencyFileGenerator)
TheDependencyFileGenerator->AttachToASTReader(*ModuleManager);
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index b8c290672e1..728032b8562 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -138,10 +138,6 @@ void Sema::addImplicitTypedef(StringRef Name, QualType T) {
}
void Sema::Initialize() {
- // Tell the AST consumer about this Sema object.
- Consumer.Initialize(Context);
-
- // FIXME: Isn't this redundant with the initialization above?
if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
SC->InitializeSema(*this);
diff --git a/clang/test/Index/index-pch-with-module.m b/clang/test/Index/index-pch-with-module.m
index 53bac1e4460..36c9c2beb47 100644
--- a/clang/test/Index/index-pch-with-module.m
+++ b/clang/test/Index/index-pch-with-module.m
@@ -18,8 +18,8 @@ int glob;
// CHECK-NOT: [indexDeclaration]
// CHECK: [importedASTFile]: {{.*}}.h.pch
-// CHECK-NEXT: [enteredMainFile]: {{.*[/\\]}}index-pch-with-module.m
// CHECK-NEXT: [startedTranslationUnit]
+// CHECK-NEXT: [enteredMainFile]: {{.*[/\\]}}index-pch-with-module.m
// CHECK-NEXT: [indexDeclaration]: kind: variable | name: glob | {{.*}} | loc: 10:5
// CHECK-NOT: [indexDeclaration]
diff --git a/clang/test/Index/skip-parsed-bodies/compile_commands.json b/clang/test/Index/skip-parsed-bodies/compile_commands.json
index 6707e84d264..30ede0db101 100644
--- a/clang/test/Index/skip-parsed-bodies/compile_commands.json
+++ b/clang/test/Index/skip-parsed-bodies/compile_commands.json
@@ -19,7 +19,8 @@
// XFAIL: mingw32,win32,windows-gnu
// RUN: c-index-test -index-compile-db %s | FileCheck %s
-// CHECK: [enteredMainFile]: t1.cpp
+// CHECK: [startedTranslationUnit]
+// CHECK-NEXT: [enteredMainFile]: t1.cpp
// CHECK: [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:9:27
@@ -34,6 +35,7 @@
// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val2'
// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val3'
+// CHECK-NEXT: [startedTranslationUnit]
// CHECK-NEXT: [enteredMainFile]: t2.cpp
// CHECK: [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
@@ -53,6 +55,7 @@
// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_tsval'
// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_impval'
+// CHECK-NEXT: [startedTranslationUnit]
// CHECK-NEXT: [enteredMainFile]: t3.cpp
// CHECK: [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
OpenPOWER on IntegriCloud