Skip to content

Commit c3321f4

Browse files
committed
SIL: verify that only loadable types are loaded and stored.
1 parent 2c0fd72 commit c3321f4

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
940940
}
941941
void checkLoadInst(LoadInst *LI) {
942942
require(LI->getType().isObject(), "Result of load must be an object");
943+
require(LI->getType().isLoadable(LI->getModule()),
944+
"Load must have a loadable type");
943945
require(LI->getOperand()->getType().isAddress(),
944946
"Load operand must be an address");
945947
require(LI->getOperand()->getType().getObjectType() == LI->getType(),
@@ -949,6 +951,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
949951
void checkStoreInst(StoreInst *SI) {
950952
require(SI->getSrc()->getType().isObject(),
951953
"Can't store from an address source");
954+
require(SI->getSrc()->getType().isLoadable(SI->getModule()),
955+
"Can't store a non loadable type");
952956
require(SI->getDest()->getType().isAddress(),
953957
"Must store to an address dest");
954958
require(SI->getDest()->getType().getObjectType() == SI->getSrc()->getType(),

test/SILOptimizer/definite_init.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ bb0:
271271
%c = mark_uninitialized [var] %ba : $*@sil_weak Optional<SomeClass> // expected-note {{variable defined here}}
272272

273273
// Invalid load to keep the alloc_box around so we can check init semantics.
274-
load %c : $*@sil_weak Optional<SomeClass> // expected-error {{used before being initialized}}
274+
load_weak %c : $*@sil_weak Optional<SomeClass> // expected-error {{used before being initialized}}
275275

276276
%f = function_ref @getSomeOptionalClass : $@convention(thin) () -> Optional<SomeClass>
277277

test/SILOptimizer/existential_type_propagation.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ bb2:
151151
// CHECK: open_existential_addr
152152
// CHECK-NEXT: witness_method
153153
// CHECK-NEXT: apply
154-
sil @existential_is_overwritten_by_store : $@convention(thin) (P) -> Int64 {
155-
bb0(%0 : $P):
154+
sil @existential_is_overwritten_by_store : $@convention(thin) (@in P) -> Int64 {
155+
bb0(%0 : $*P):
156156
%2 = alloc_stack $P, let, name "p"
157157
%3 = init_existential_addr %2 : $*P, $X
158158
%6 = integer_literal $Builtin.Int64, 27
159159
%7 = struct $Int64 (%6 : $Builtin.Int64)
160160
%8 = struct $X (%7 : $Int64)
161161
store %8 to %3 : $*X
162162
destroy_addr %2 : $*P
163-
store %0 to %2 : $*P
163+
copy_addr [take] %0 to %2 : $*P // id: %5
164164
%10 = open_existential_addr %2 : $*P to $*@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P
165165
%11 = witness_method $@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P, #P.foo!1, %10 : $*@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
166166
%12 = apply %11<@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P>(%10) : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64

0 commit comments

Comments
 (0)