Skip to content

Commit f8dadef

Browse files
committed
[CodeGen] Keep track of eagerly emitted globals
An inline virtual function must be emitted, but we need to remember it and emit the same definition again in the future in case later LLVM optimizations stripped it from the Module. The added test case shows the problem; before this patch, it would fail with: Symbols not found: [ _ZN1AD0Ev, _ZN1AD1Ev ] Differential Revision: https://reviews.llvm.org/D156537
1 parent 3c24326 commit f8dadef

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
36583658
if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
36593659
// Emit the definition if it can't be deferred.
36603660
EmitGlobalDefinition(GD);
3661+
addEmittedDeferredDecl(GD);
36613662
return;
36623663
}
36633664

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// REQUIRES: host-supports-jit
2+
// UNSUPPORTED: system-aix
3+
// RUN: cat %s | clang-repl | FileCheck %s
4+
// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
5+
6+
extern "C" int printf(const char *, ...);
7+
8+
struct A { int a; A(int a) : a(a) {} virtual ~A(); };
9+
10+
// Then define the virtual destructor as inline out-of-line, in a separate
11+
// PartialTranslationUnit.
12+
inline A::~A() { printf("~A(%d)\n", a); }
13+
14+
// Create one instance with new and delete it.
15+
A *a1 = new A(1);
16+
delete a1;
17+
// CHECK: ~A(1)
18+
19+
// Also create one global that will be auto-destructed.
20+
A a2(2);
21+
// CHECK: ~A(2)

0 commit comments

Comments
 (0)