Skip to content

Commit 0f428c2

Browse files
committed
alias-analysis test
1 parent b8f3f9c commit 0f428c2

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/SILOptimizer/alias-analysis.sil

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// RUN: %target-sil-opt %s -aa-kind=all -aa-dump -o /dev/null | %FileCheck %s
2+
3+
// General black-box alias analysis tests. White-box unit tests are
4+
// specific to the aa-kind, such as basic-aa.sil and typed-access-tb-aa.sil.
5+
6+
// REQUIRES: asserts
7+
8+
sil_stage canonical
9+
10+
import Swift
11+
import SwiftShims
12+
import Builtin
13+
14+
struct MyStruct {
15+
@_hasStorage @_hasInitialValue var i: Int64 { get set }
16+
@_hasStorage @_hasInitialValue var j: Int64 { get set }
17+
}
18+
19+
struct OuterStruct {
20+
@_hasStorage @_hasInitialValue var s: MyStruct { get set }
21+
}
22+
23+
// Test overlaping access on a different path; the user has misused an index offset
24+
// CHECK-LABEL: @testOffsetBehindProjection
25+
// CHECK: PAIR #28.
26+
// CHECK: %4 = load %3 : $*Int64
27+
// CHECK: %6 = load %5 : $*Int64
28+
// CHECK: MayAlias
29+
sil shared @testOffsetBehindProjection : $@convention(thin) (@inout MyStruct) -> () {
30+
bb0(%0 : $*MyStruct):
31+
%1 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
32+
%2 = integer_literal $Builtin.Word, 1
33+
%3 = index_addr %1 : $*Int64, %2 : $Builtin.Word
34+
%4 = load %3 : $*Int64
35+
// load from a different subobject overlaps
36+
%5 = struct_element_addr %0 : $*MyStruct, #MyStruct.j
37+
%6 = load %5 : $*Int64
38+
%99 = tuple ()
39+
return %99 : $()
40+
}
41+
42+
// CHECK-LABEL: @testOffsetsBehindProjectionOverlap
43+
// CHECK: PAIR #28.
44+
// CHECK: %3 = load %2 : $*Int64
45+
// CHECK: %7 = load %6 : $*Int64
46+
// CHECK: MayAlias
47+
sil shared @testOffsetsBehindProjectionOverlap : $@convention(thin) (@inout OuterStruct) -> () {
48+
bb0(%0 : $*OuterStruct):
49+
%1 = struct_element_addr %0 : $*OuterStruct, #OuterStruct.s
50+
%2 = struct_element_addr %1 : $*MyStruct, #MyStruct.i
51+
%3 = load %2 : $*Int64
52+
// Loading from a different index within the same subobject still appears to overlap.
53+
// Indexing from a subobject is always considered an unknown index.
54+
%4 = integer_literal $Builtin.Word, 1
55+
%5 = index_addr %1 : $*MyStruct, %4 : $Builtin.Word
56+
%6 = struct_element_addr %5 : $*MyStruct, #MyStruct.i
57+
%7 = load %6 : $*Int64
58+
%99 = tuple ()
59+
return %99 : $()
60+
}

0 commit comments

Comments
 (0)