Skip to content

Commit 4181026

Browse files
authored
Merge pull request #4453 from trentxintong/LLVMSwiftARC
Fix a globalvariable initializer bug in LLVMSwiftARC
2 parents e12e730 + 026cee2 commit 4181026

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/LLVMPasses/LLVMARCOpts.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,10 @@ static DtorKind analyzeDestructor(Value *P) {
545545

546546
// We have to have a known heap metadata value, reject dynamically computed
547547
// ones, or places
548+
// Also, make sure we have a definitive initializer for the global.
548549
GlobalVariable *GV = dyn_cast<GlobalVariable>(P->stripPointerCasts());
549-
if (GV == 0 || GV->mayBeOverridden()) return DtorKind::Unknown;
550+
if (GV == 0 || !GV->hasDefinitiveInitializer())
551+
return DtorKind::Unknown;
550552

551553
ConstantStruct *CS = dyn_cast_or_null<ConstantStruct>(GV->getInitializer());
552554
if (CS == 0 || CS->getNumOperands() == 0) return DtorKind::Unknown;

test/LLVMPasses/allocation-deletion.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,19 @@ entry:
8181
; CHECK-NEXT: ret void
8282

8383

84+
; external_dtor_alloc_eliminate - Make sure we can not eliminate the allocation
85+
; because we know nothing about the type of the allocation.
86+
@external_dtor_metadata = external global %swift.heapmetadata, align 8
87+
define void @external_dtor_alloc_eliminate() nounwind {
88+
entry:
89+
%0 = tail call noalias %swift.refcounted* @swift_allocObject(%swift.heapmetadata* nonnull @external_dtor_metadata, i64 24, i64 8) nounwind
90+
tail call void @swift_release(%swift.refcounted* %0) nounwind
91+
ret void
92+
}
93+
94+
; CHECK: @external_dtor_alloc_eliminate
95+
; CHECK-NEXT: entry:
96+
; CHECK-NEXT: swift_allocObject
97+
; CHECK-NEXT: swift_release
98+
; CHECK-NEXT: ret void
8499

0 commit comments

Comments
 (0)