Skip to content

Commit 7574c1f

Browse files
committed
Fix AccessUtils Value.referenceRoot to handle ForwardingInstructions.
This fixes all analyses that use AccessUtils in the presence of new forwarding instructions. This is also needed for consistency with the C++ source base. And for general sanity. Utilities that walk the use-def chain should never hard-code a list of opcodes that happened to work with some specific pass. Passes should never assume that a basic SIL utility handles specific SIL operations a certain way. Instead, the utility needs to be defined in terms of SIL semantics. In this case, the utility is supposed to handle all instructions that semantically forward ownership of a reference.
1 parent 56126e9 commit 7574c1f

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

SwiftCompilerSources/Sources/SIL/Utilities/AccessUtils.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -546,20 +546,16 @@ extension Value {
546546
public var referenceRoot: Value {
547547
var value: Value = self
548548
while true {
549-
switch value {
550-
case is BeginBorrowInst, is CopyValueInst, is MoveValueInst,
551-
is EndInitLetRefInst,
552-
is BeginDeallocRefInst,
553-
is UpcastInst, is UncheckedRefCastInst, is EndCOWMutationInst:
554-
value = (value as! Instruction).operands[0].value
555-
case let mvr as MultipleValueInstructionResult:
556-
guard let bcm = mvr.parentInstruction as? BeginCOWMutationInst else {
557-
return value
558-
}
559-
value = bcm.instance
560-
default:
561-
return value
549+
if let forward = value.forwardingInstruction, forward.preservesIdentity,
550+
let operand = forward.singleForwardedOperand {
551+
value = operand.value
552+
continue
553+
}
554+
if let transition = value.definingInstruction as? OwnershipTransitionInstruction {
555+
value = transition.operand.value
556+
continue
562557
}
558+
return value
563559
}
564560
}
565561
}

0 commit comments

Comments
 (0)