Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 1f0b0f9

Browse files
committed
Stop handling interesting deserialized decls after HandleTranslationUnit
Other AST consumers can deserialize interesting decls that we might codegen, but they won't make it to the final object file and can trigger assertions in debug information generation after finalization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288221 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c689f66 commit 1f0b0f9

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Diff for: lib/CodeGen/CodeGenAction.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ namespace clang {
5353
Timer LLVMIRGeneration;
5454
unsigned LLVMIRGenerationRefCount;
5555

56+
/// True if we've finished generating IR. This prevents us from generating
57+
/// additional LLVM IR after emitting output in HandleTranslationUnit. This
58+
/// can happen when Clang plugins trigger additional AST deserialization.
59+
bool IRGenFinished = false;
60+
5661
std::unique_ptr<CodeGenerator> Gen;
5762

5863
SmallVector<std::pair<unsigned, std::unique_ptr<llvm::Module>>, 4>
@@ -147,6 +152,12 @@ namespace clang {
147152
LLVMIRGeneration.stopTimer();
148153
}
149154

155+
void HandleInterestingDecl(DeclGroupRef D) {
156+
// Ignore interesting decls from the AST reader after IRGen is finished.
157+
if (!IRGenFinished)
158+
HandleTopLevelDecl(D);
159+
}
160+
150161
void HandleTranslationUnit(ASTContext &C) override {
151162
{
152163
PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
@@ -163,6 +174,8 @@ namespace clang {
163174
if (LLVMIRGenerationRefCount == 0)
164175
LLVMIRGeneration.stopTimer();
165176
}
177+
178+
IRGenFinished = true;
166179
}
167180

168181
// Silently ignore if we weren't initialized for some reason.

Diff for: test/Frontend/plugin-vs-debug-info.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This test uses PrintFunctionNames with -fdelayed-template-parsing because it
2+
// happens to use a RecursiveASTVisitor that forces deserialization of AST
3+
// files.
4+
//
5+
// RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch -o %t.pch %s
6+
// RUN: %clang_cc1 -load %llvmshlibdir/PrintFunctionNames%pluginext \
7+
// RUN: -add-plugin print-fns -std=c++14 -include-pch %t.pch %s -emit-llvm \
8+
// RUN: -fdelayed-template-parsing -debug-info-kind=limited \
9+
// RUN: -o %t.ll 2>&1 | FileCheck --check-prefix=DECLS %s
10+
// RUN: FileCheck --check-prefix=IR %s < %t.ll
11+
//
12+
// REQUIRES: plugins, examples
13+
14+
// DECLS: top-level-decl: "func"
15+
16+
// IR: define {{.*}}void @_Z4funcv()
17+
18+
#ifndef HEADER
19+
#define HEADER
20+
21+
struct nullopt_t {
22+
constexpr explicit nullopt_t(int) {}
23+
};
24+
constexpr nullopt_t nullopt(0);
25+
26+
#else
27+
28+
void func() { }
29+
30+
#endif

0 commit comments

Comments
 (0)