Skip to content

Commit ddf8b45

Browse files
committed
Fix use-after-free of deleted debug instructions in Canonicalize
1 parent dc9d132 commit ddf8b45

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/SIL/SILFunction.h"
2727
#include "swift/SIL/SILInstruction.h"
2828
#include "swift/SILOptimizer/Analysis/SimplifyInstruction.h"
29+
#include "swift/SILOptimizer/Utils/DebugOptUtils.h"
2930
#include "llvm/ADT/Statistic.h"
3031
#include "llvm/Support/Debug.h"
3132

@@ -521,7 +522,7 @@ eliminateUnneededForwardingUnarySingleValueInst(SingleValueInstruction *inst,
521522
for (auto *use : getNonDebugUses(inst))
522523
if (!isa<DestroyValueInst>(use->getUser()))
523524
return next;
524-
deleteAllDebugUses(inst);
525+
deleteAllDebugUses(inst, pass.callbacks);
525526
SILValue op = inst->getOperand(0);
526527
inst->replaceAllUsesWith(op);
527528
pass.notifyHasNewUsers(op);

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,3 +4561,19 @@ bb1(%2 : @owned $FakeOptional<Builtin.NativeObject>):
45614561
%9999 = tuple()
45624562
return %9999 : $()
45634563
}
4564+
4565+
// CHECK-LABEL: sil [ossa] @test_useafterfree_debuginstdelete :
4566+
// CHECK-NOT: upcast
4567+
// CHECK-NOT: unchecked_ref_cast
4568+
// CHECK-LABEL: } // end sil function 'test_useafterfree_debuginstdelete'
4569+
sil [ossa] @test_useafterfree_debuginstdelete : $@convention(method) (@owned E) -> () {
4570+
bb0(%0 : @owned $E):
4571+
%1 = upcast %0 : $E to $B
4572+
debug_value %1 : $B
4573+
%2 = unchecked_ref_cast %1 : $B to $Builtin.NativeObject
4574+
debug_value %2 : $Builtin.NativeObject
4575+
destroy_value %2 : $Builtin.NativeObject
4576+
%res = tuple ()
4577+
return %res : $()
4578+
}
4579+

0 commit comments

Comments
 (0)