Skip to content

Fix a globalvariable initializer bug in LLVMSwiftARC #4453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/LLVMPasses/LLVMARCOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,10 @@ static DtorKind analyzeDestructor(Value *P) {

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

ConstantStruct *CS = dyn_cast_or_null<ConstantStruct>(GV->getInitializer());
if (CS == 0 || CS->getNumOperands() == 0) return DtorKind::Unknown;
Expand Down
15 changes: 15 additions & 0 deletions test/LLVMPasses/allocation-deletion.ll
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,19 @@ entry:
; CHECK-NEXT: ret void


; external_dtor_alloc_eliminate - Make sure we can not eliminate the allocation
; because we know nothing about the type of the allocation.
@external_dtor_metadata = external global %swift.heapmetadata, align 8
define void @external_dtor_alloc_eliminate() nounwind {
entry:
%0 = tail call noalias %swift.refcounted* @swift_allocObject(%swift.heapmetadata* nonnull @external_dtor_metadata, i64 24, i64 8) nounwind
tail call void @swift_release(%swift.refcounted* %0) nounwind
ret void
}

; CHECK: @external_dtor_alloc_eliminate
; CHECK-NEXT: entry:
; CHECK-NEXT: swift_allocObject
; CHECK-NEXT: swift_release
; CHECK-NEXT: ret void