1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// RUN: %target-sil-opt %s -aa-kind=all -aa-dump -o /dev/null | %FileCheck %s
// General black-box alias analysis tests. White-box unit tests are
// specific to the aa-kind, such as basic-aa.sil and typed-access-tb-aa.sil.
// REQUIRES: asserts
sil_stage canonical
import Swift
import SwiftShims
import Builtin
struct MyStruct {
@_hasStorage @_hasInitialValue var i: Int64 { get set }
@_hasStorage @_hasInitialValue var j: Int64 { get set }
}
struct OuterStruct {
@_hasStorage @_hasInitialValue var s: MyStruct { get set }
}
// Test overlapping access on a different path; the user has misused an index offset
// CHECK-LABEL: @testOffsetBehindProjection
// CHECK: PAIR #23.
// CHECK: %3 = index_addr %1 : $*Int64, %2 : $Builtin.Word
// CHECK: %5 = struct_element_addr %0 : $*MyStruct, #MyStruct.j
// CHECK: NoAlias
sil shared @testOffsetBehindProjection : $@convention(thin) (@inout MyStruct) -> () {
bb0(%0 : $*MyStruct):
%1 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
%2 = integer_literal $Builtin.Word, 1
%3 = index_addr %1 : $*Int64, %2 : $Builtin.Word
%4 = load %3 : $*Int64
// load from a different subobject overlaps
%5 = struct_element_addr %0 : $*MyStruct, #MyStruct.j
%6 = load %5 : $*Int64
%99 = tuple ()
return %99 : $()
}
// CHECK-LABEL: @testOffsetsBehindProjectionOverlap
// CHECK: PAIR #21.
// CHECK: %2 = struct_element_addr %1 : $*MyStruct, #MyStruct.i
// CHECK: %6 = struct_element_addr %5 : $*MyStruct, #MyStruct.i
// CHECK: NoAlias
sil shared @testOffsetsBehindProjectionOverlap : $@convention(thin) (@inout OuterStruct) -> () {
bb0(%0 : $*OuterStruct):
%1 = struct_element_addr %0 : $*OuterStruct, #OuterStruct.s
%2 = struct_element_addr %1 : $*MyStruct, #MyStruct.i
%3 = load %2 : $*Int64
// Loading from a different index within the same subobject still appears to overlap.
// Indexing from a subobject is always considered an unknown index.
%4 = integer_literal $Builtin.Word, 1
%5 = index_addr %1 : $*MyStruct, %4 : $Builtin.Word
%6 = struct_element_addr %5 : $*MyStruct, #MyStruct.i
%7 = load %6 : $*Int64
%99 = tuple ()
return %99 : $()
}
// CHECK-LABEL: @testIndexOf0
// CHECK: PAIR #8.
// CHECK: %1 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
// CHECK: %3 = index_addr %0 : $*MyStruct, %2 : $Builtin.Word
// CHECK: MayAlias
// CHECK: PAIR #9.
// CHECK: %1 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
// CHECK: %4 = struct_element_addr %3 : $*MyStruct, #MyStruct.i
// CHECK: MustAlias
sil @testIndexOf0 : $@convention(thin) (@inout MyStruct) -> () {
bb0(%0 : $*MyStruct):
%1 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
%2 = integer_literal $Builtin.Word, 0
%3 = index_addr %0 : $*MyStruct, %2 : $Builtin.Word
%4 = struct_element_addr %3 : $*MyStruct, #MyStruct.i
fix_lifetime %1 : $*Int64
fix_lifetime %4 : $*Int64
%99 = tuple ()
return %99 : $()
}
// CHECK-LABEL: @testUnknownIndex
// CHECK: PAIR #12.
// CHECK: %2 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
// CHECK: %3 = index_addr %0 : $*MyStruct, %1 : $Builtin.Word
// CHECK: MayAlias
// CHECK: PAIR #13.
// CHECK: %2 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
// CHECK: %4 = struct_element_addr %3 : $*MyStruct, #MyStruct.i
// CHECK: MayAlias
sil @testUnknownIndex : $@convention(thin) (@inout MyStruct, Builtin.Word) -> () {
bb0(%0 : $*MyStruct, %1 : $Builtin.Word):
%2 = struct_element_addr %0 : $*MyStruct, #MyStruct.i
%3 = index_addr %0 : $*MyStruct, %1 : $Builtin.Word
%4 = struct_element_addr %3 : $*MyStruct, #MyStruct.i
fix_lifetime %2 : $*Int64
fix_lifetime %4 : $*Int64
%99 = tuple ()
return %99 : $()
}
|