Skip to content

Commit 0b41bd2

Browse files
authored
Merge pull request #72985 from eeckstein/fix-diagnose-unreachable
DiagnoseUnreachable: consider borrowed-from instructions when deleting block arguments
2 parents 9582f5d + 89b38d1 commit 0b41bd2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/SIL/SILUndef.h"
2525
#include "swift/SIL/TerminatorUtils.h"
2626
#include "swift/SIL/BasicBlockDatastructures.h"
27+
#include "swift/SIL/OwnershipUtils.h"
2728
#include "swift/SILOptimizer/PassManager/Passes.h"
2829
#include "swift/SILOptimizer/PassManager/Transforms.h"
2930
#include "swift/SILOptimizer/Utils/BasicBlockOptUtils.h"
@@ -190,7 +191,12 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
190191
SILArgument *Arg = *AI;
191192

192193
// We were able to fold, so all users should use the new folded value.
193-
Arg->replaceAllUsesWith(Args[Idx]);
194+
if (auto *bfi = getBorrowedFromUser(Arg)) {
195+
bfi->replaceAllUsesWith(Args[Idx]);
196+
bfi->eraseFromParent();
197+
} else {
198+
Arg->replaceAllUsesWith(Args[Idx]);
199+
}
194200
++NumBasicBlockArgsPropagated;
195201
}
196202

test/SILOptimizer/diagnose_unreachable.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnose-unreachable -sil-print-debuginfo | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -update-borrowed-from -diagnose-unreachable -sil-print-debuginfo | %FileCheck %s
22

33
import Builtin
44
import Swift

0 commit comments

Comments
 (0)