[region-isolation] Fix crash due to missing visitVectorBaseAddrInst case

Credit to https://github.com/stzn for initial work on the patch.

rdar://151401230
This commit is contained in:
stzn
2025-05-18 19:01:50 +09:00
committed by Michael Gottesman
parent 62c886e13b
commit 660263cf2c
3 changed files with 59 additions and 3 deletions

View File

@@ -141,7 +141,16 @@ struct AddressBaseComputingVisitor
return SILValue();
}
SILValue visitNonAccess(SILValue) { return SILValue(); }
SILValue visitNonAccess(SILValue value) {
// For now since it is late in 6.2, work around vector base addr not being
// treated as a projection.
if (auto *v = dyn_cast<VectorBaseAddrInst>(value)) {
isProjectedFromAggregate = true;
return v->getOperand();
}
return SILValue();
}
SILValue visitPhi(SILPhiArgument *phi) {
llvm_unreachable("Should never hit this");
@@ -312,6 +321,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
case SILInstructionKind::UncheckedEnumDataInst:
case SILInstructionKind::StructElementAddrInst:
case SILInstructionKind::TupleElementAddrInst:
case SILInstructionKind::VectorBaseAddrInst:
return true;
case SILInstructionKind::MoveValueInst:
// Look through if it isn't from a var decl.

View File

@@ -681,4 +681,45 @@ bb2:
bb3:
%9999 = tuple ()
return %9999 : $()
}
}
// CHECK-LABEL: begin running test 1 of 1 on alloc_stack_inline_array_sendable: sil_regionanalysis_underlying_tracked_value with: @trace[0]
// CHECK: TrackableValue. State: TrackableValueState[id: 0][is_no_alias: no][is_sendable: yes][region_value_kind: disconnected].
// CHECK: Rep Value: %2 = vector_base_addr %1
// CHECK: end running test 1 of 1 on alloc_stack_inline_array_sendable: sil_regionanalysis_underlying_tracked_value with: @trace[0]
sil [ossa] @alloc_stack_inline_array_sendable : $@convention(thin) () -> () {
bb0:
specify_test "sil_regionanalysis_underlying_tracked_value @trace[0]"
%0 = alloc_stack $InlineArray<1, UInt8>
%1 = struct_element_addr %0: $*InlineArray<1, UInt8>, #InlineArray._storage
%2 = vector_base_addr %1 : $*Builtin.FixedArray<1, UInt8>
%3 = integer_literal $Builtin.Int8, 0
%4 = struct $UInt8 (%3)
store %4 to [trivial] %2
%6 = load [trivial] %0
dealloc_stack %0
debug_value [trace] %2
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: begin running test 1 of 1 on alloc_stack_inline_array_nonsendable: sil_regionanalysis_underlying_tracked_value with: @trace[0]
// CHECK: TrackableValue. State: TrackableValueState[id: 0][is_no_alias: yes][is_sendable: no][region_value_kind: disconnected].
// CHECK: Rep Value: %1 = alloc_stack $InlineArray
// CHECK: end running test 1 of 1 on alloc_stack_inline_array_nonsendable: sil_regionanalysis_underlying_tracked_value with: @trace[0]
sil [ossa] @alloc_stack_inline_array_nonsendable : $@convention(thin) (@owned NonSendableKlass) -> () {
bb0(%arg : @owned $NonSendableKlass):
specify_test "sil_regionanalysis_underlying_tracked_value @trace[0]"
%0 = alloc_stack $InlineArray<1, NonSendableKlass>
%1 = struct_element_addr %0: $*InlineArray<1, NonSendableKlass>, #InlineArray._storage
%2 = vector_base_addr %1 : $*Builtin.FixedArray<1, NonSendableKlass>
store %arg to [init] %2
%6 = load [take] %0
destroy_value %6
dealloc_stack %0
debug_value [trace] %2
%7 = tuple ()
return %7 : $()
}

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -swift-version 6 -parse-as-library %s -emit-sil -o /dev/null -verify
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -swift-version 6 -disable-availability-checking -parse-as-library %s -emit-sil -o /dev/null -verify
// REQUIRES: asserts
// REQUIRES: concurrency
@@ -135,3 +135,8 @@ func testGenericResults() async {
let _: NonSendable = await mainActorGenericReturnNonSendable()
// expected-error @-1 {{non-Sendable 'NonSendable'-typed result can not be returned from main actor-isolated global function 'mainActorGenericReturnNonSendable()' to nonisolated context}}
}
// https://github.com/swiftlang/swift/issues/81534
func testInlineArray() {
let _: InlineArray<_, UInt8> = [0]
}