Skip to content

Commit 1f669d3

Browse files
hahnjotru
authored andcommitted
[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 ] This reapplies commit f8dadef, reverted in commit 0e17372, but disables RTTI in the test to avoid problems on Windows. Differential Revision: https://reviews.llvm.org/D156537 (cherry picked from commit c861d32)
1 parent 0a3a919 commit 1f669d3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3645,6 +3645,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
36453645
if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
36463646
// Emit the definition if it can't be deferred.
36473647
EmitGlobalDefinition(GD);
3648+
addEmittedDeferredDecl(GD);
36483649
return;
36493650
}
36503651

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

0 commit comments

Comments
 (0)