Skip to content

Fix debug info in DeadObjectElimination in OSSA #75807

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 10, 2024
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
5 changes: 3 additions & 2 deletions lib/SILOptimizer/Transforms/DeadObjectElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ bool DeadObjectElimination::processAllocStack(AllocStackInst *ASI) {
return false;
}

for (auto *I : UsersToRemove)
salvageDebugInfo(I);

if (ASI->getFunction()->hasOwnership()) {
for (auto *user : UsersToRemove) {
auto *store = dyn_cast<StoreInst>(user);
Expand All @@ -1019,8 +1022,6 @@ bool DeadObjectElimination::processAllocStack(AllocStackInst *ASI) {
}
}

for (auto *I : UsersToRemove)
salvageDebugInfo(I);
// Remove the AllocRef and all of its users.
removeInstructions(
ArrayRef<SILInstruction*>(UsersToRemove.begin(), UsersToRemove.end()));
Expand Down
23 changes: 23 additions & 0 deletions test/SILOptimizer/dead_array_elim_ossa.sil
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class TrivialDestructor {
deinit { }
}

class Klass {}

struct NonTrivialStruct {
var k : Klass
init()
}

// Remove a dead array.
// rdar://20980377 Add dead array elimination to DeadObjectElimination
// Swift._allocateUninitializedArray <A> (Builtin.Word) -> (Swift.Array<A>, Builtin.RawPointer)
Expand Down Expand Up @@ -167,3 +174,19 @@ bb2:
return %18 : $()
}

// CHECK-LABEL: sil [ossa] @dead_debuginfo
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'dead_debuginfo'
sil [ossa] @dead_debuginfo : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
%1 = alloc_stack [lexical] [var_decl] $NonTrivialStruct, var, name "x", type $NonTrivialStruct
%2 = integer_literal $Builtin.Int64, 0
%4 = struct $NonTrivialStruct (%0 : $Klass)
apply undef(%4) : $@convention(thin) (@guaranteed NonTrivialStruct) -> ()
store %4 to [init] %1 : $*NonTrivialStruct
destroy_addr %1 : $*NonTrivialStruct
dealloc_stack %1 : $*NonTrivialStruct
%t = tuple ()
return %t : $()
}