Skip to content

Commit 5e81948

Browse files
authored
Merge pull request #8713 from rjmccall/access-of-global-variable
Fix SILVerifier for begin_access on global variables
2 parents ee8f98a + b50c1b0 commit 5e81948

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
12641264
isa<AllocStackInst>(op) ||
12651265
isa<ProjectBoxInst>(op) ||
12661266
isa<RefElementAddrInst>(op) ||
1267+
isa<PointerToAddressInst>(op) ||
12671268
isa<SILFunctionArgument>(op) ||
12681269
isa<BeginAccessInst>(op) ||
12691270
isa<MarkUninitializedInst>(op),

test/SILGen/access_marker_gen.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ public func modifyAndReadS() {
5656
s.i = 42
5757
takeS(s)
5858
}
59+
60+
var global = S(i: 0, o: nil)
61+
62+
func readGlobal() -> AnyObject? {
63+
return global.o
64+
}
65+
66+
// CHECK-LABEL: sil hidden @_T017access_marker_gen10readGlobals9AnyObject_pSgyF
67+
// CHECK: [[ADDRESSOR:%.*]] = function_ref @_T017access_marker_gen6globalAA1SVfau :
68+
// CHECK-NEXT: [[T0:%.*]] = apply [[ADDRESSOR]]()
69+
// CHECK-NEXT: [[T1:%.*]] = pointer_to_address [[T0]] : $Builtin.RawPointer to [strict] $*S
70+
// CHECK-NEXT: [[T2:%.*]] = begin_access [read] [dynamic] [[T1]]
71+
// CHECK-NEXT: [[T3:%.*]] = struct_element_addr [[T2]] : $*S, #S.o
72+
// CHECK-NEXT: [[T4:%.*]] = load [copy] [[T3]]
73+
// CHECK-NEXT: end_access [[T2]]
74+
// CHECK-NEXT: return [[T4]]

0 commit comments

Comments
 (0)