Skip to content

Commit 83e176b

Browse files
authored
Merge pull request #30913 from atrick/fix-assert-termoper
2 parents 75548c3 + 8636c39 commit 83e176b

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

include/swift/SIL/MemAccessUtils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ SingleValueInstruction *isAccessProjection(SILValue v);
7979
SILValue getAddressAccess(SILValue v);
8080

8181
/// Convenience for stripAccessMarkers(getAddressAccess(v)).
82-
inline SILValue getAccessedAddress(SILValue v) {
83-
return stripAccessMarkers(getAddressAccess(v));
84-
}
82+
SILValue getAccessedAddress(SILValue v);
8583

8684
/// Return true if \p accessedAddress points to a let-variable.
8785
///

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ SILValue swift::getAddressAccess(SILValue v) {
5858
}
5959
}
6060

61+
SILValue swift::getAccessedAddress(SILValue v) {
62+
while (true) {
63+
SILValue v2 = stripAccessMarkers(getAddressAccess(v));
64+
if (v2 == v)
65+
return v;
66+
v = v2;
67+
}
68+
}
69+
6170
bool swift::isLetAddress(SILValue accessedAddress) {
6271
assert(accessedAddress == getAccessedAddress(accessedAddress)
6372
&& "caller must find the address root");

test/SILOptimizer/mem-behavior-all.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,30 @@ bb0(%0 : $C):
141141
%8 = tuple ()
142142
return %8 : $()
143143
}
144+
145+
// ===-----------------------------------------------------------------------===
146+
// Test that isLetAccess does not assert on nested access markers with
147+
// interprosed projections.
148+
149+
struct Int64Wrapper {
150+
var val : Int64
151+
}
152+
153+
// CHECK-LABEL: @testNestedAccessWithInterposedProjection
154+
// CHECK: PAIR #2.
155+
// CHECK: %1 = begin_access [modify] [static] %0 : $*Int64Wrapper // users: %7, %2
156+
// CHECK: %3 = begin_access [read] [static] %2 : $*Int64 // users: %6, %4
157+
// CHECK: r=0,w=1,se=1
158+
// CHECK: PAIR #3.
159+
sil @testNestedAccessWithInterposedProjection : $@convention(thin) (@inout Int64Wrapper) -> () {
160+
bb0(%0 : $*Int64Wrapper):
161+
%1 = begin_access [modify] [static] %0 : $*Int64Wrapper
162+
%2 = struct_element_addr %1 : $*Int64Wrapper, #Int64Wrapper.val
163+
%3 = begin_access [read] [static] %2 : $*Int64
164+
%4 = struct_element_addr %3 : $*Int64, #Int64._value
165+
%5 = load %4 : $*Builtin.Int64
166+
end_access %3 : $*Int64
167+
end_access %1 : $*Int64Wrapper
168+
%8 = tuple ()
169+
return %8 : $()
170+
}

0 commit comments

Comments
 (0)