Skip to content

Commit b59e965

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 9777c3f commit b59e965

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
@@ -362,7 +362,9 @@ static AccessedStorageResult getAccessedStorageFromAddress(SILValue sourceAddr)
362362

363363
// Access to a Builtin.RawPointer. Treat this like the inductive cases
364364
// above because some RawPointers originate from identified locations. See
365-
// the special case for global addressors, which return RawPointer, above.
365+
// the special case for global addressors, which return RawPointer,
366+
// above. AddressToPointer is also handled because it results from inlining a
367+
// global addressor without folding the AddressToPointer->PointerToAddress.
366368
//
367369
// If the inductive search does not find a valid addressor, it will
368370
// eventually reach the default case that returns in invalid location. This
@@ -381,6 +383,7 @@ static AccessedStorageResult getAccessedStorageFromAddress(SILValue sourceAddr)
381383
// marks debug VarDecl access as 'Unsafe' and SIL passes don't need the
382384
// AccessedStorage for 'Unsafe' access.
383385
case ValueKind::PointerToAddressInst:
386+
case ValueKind::AddressToPointerInst:
384387
return AccessedStorageResult::incomplete(
385388
cast<SingleValueInstruction>(sourceAddr)->getOperand(0));
386389

@@ -420,6 +423,8 @@ AccessedStorage swift::findAccessedStorage(SILValue sourceAddr) {
420423
storage = result.getStorage();
421424
continue;
422425
}
426+
// `storage` may still be invalid. If both `storage` and `result` are
427+
// invalid, this check passes, but we return an invalid storage below.
423428
if (!accessingIdenticalLocations(storage.getValue(), result.getStorage()))
424429
return AccessedStorage();
425430
}

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)