Skip to content

Commit ae77b9c

Browse files
committed
Fix getAccessedStorageFromAddress to handle AddressToPointer.
This pattern is normally folded away: %ga = global_addr @Gvar : $*Int64 %ptr = address_to_pointer %ga : $*Int64 to $Builtin.RawPointer %adr = pointer_to_address %ptr : $Builtin.RawPointer to [strict] $*Int64 %access = begin_access [read] [dynamic] [no_nested_conflict] %adr : $*Int64 However, now that we handle address type phi arguments in the SIL verifier, we could see this pattern. [In the long term, when address-type phis are universally prohibited, all of this stuff becomes irrelevant.] Fixes <rdar://47555992> [Source Compat] AudioKit: SIL verification failed: Unknown formal access pattern: storage.
1 parent 0d2be92 commit ae77b9c

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/SIL/MemAccessUtils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ static AccessedStorageResult getAccessedStorageFromAddress(SILValue sourceAddr)
374374

375375
// Access to a Builtin.RawPointer. Treat this like the inductive cases
376376
// above because some RawPointers originate from identified locations. See
377-
// the special case for global addressors, which return RawPointer, above.
377+
// the special case for global addressors, which return RawPointer,
378+
// above. AddressToPointer is also handled because it results from inlining a
379+
// global addressor without folding the AddressToPointer->PointerToAddress.
378380
//
379381
// If the inductive search does not find a valid addressor, it will
380382
// eventually reach the default case that returns in invalid location. This
@@ -393,6 +395,7 @@ static AccessedStorageResult getAccessedStorageFromAddress(SILValue sourceAddr)
393395
// marks debug VarDecl access as 'Unsafe' and SIL passes don't need the
394396
// AccessedStorage for 'Unsafe' access.
395397
case ValueKind::PointerToAddressInst:
398+
case ValueKind::AddressToPointerInst:
396399
return AccessedStorageResult::incomplete(
397400
cast<SingleValueInstruction>(sourceAddr)->getOperand(0));
398401

@@ -432,6 +435,8 @@ AccessedStorage swift::findAccessedStorage(SILValue sourceAddr) {
432435
storage = result.getStorage();
433436
continue;
434437
}
438+
// `storage` may still be invalid. If both `storage` and `result` are
439+
// invalid, this check passes, but we return an invalid storage below.
435440
if (!accessingIdenticalLocations(storage.getValue(), result.getStorage()))
436441
return AccessedStorage();
437442
}

test/SILOptimizer/accessed_storage_analysis.sil

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,41 @@ bb3(%phi : $*Float):
661661
%v = tuple ()
662662
return %v : $()
663663
}
664+
665+
// Test an inlined global variable addressor after simplify-cfg has
666+
// cloned the call to the addressor.
667+
// <rdar://problem/47555992> SIL verification failed: Unknown formal access pattern
668+
// CHECK-LABEL: @testClonedGlobalAddressor
669+
// CHECK: [read] [no_nested_conflict] Global // gvar
670+
// CHECK: sil_global hidden @gvar
671+
var gvar: Int64
672+
673+
public func foo() -> Int64
674+
675+
sil_global hidden @gvar : $Int64 = {
676+
%0 = integer_literal $Builtin.Int64, 0
677+
%initval = struct $Int (%0 : $Builtin.Int64)
678+
}
679+
680+
sil @testClonedGlobalAddressor : $@convention(thin) () -> Int64 {
681+
bb0:
682+
cond_br undef, bb1, bb2
683+
684+
bb1:
685+
%1 = global_addr @gvar : $*Int64
686+
%2 = address_to_pointer %1 : $*Int64 to $Builtin.RawPointer
687+
br bb3(%2 : $Builtin.RawPointer)
688+
689+
bb2:
690+
%4 = global_addr @gvar : $*Int64
691+
%5 = address_to_pointer %4 : $*Int64 to $Builtin.RawPointer
692+
br bb3(%5 : $Builtin.RawPointer)
693+
694+
// %7
695+
bb3(%7 : $Builtin.RawPointer):
696+
%8 = pointer_to_address %7 : $Builtin.RawPointer to [strict] $*Int64
697+
%9 = begin_access [read] [dynamic] [no_nested_conflict] %8 : $*Int64
698+
%10 = load %9 : $*Int64
699+
end_access %9 : $*Int64
700+
return %10 : $Int64
701+
}

0 commit comments

Comments
 (0)