Skip to content

Commit

Permalink
SIL: verify that only loadable types are loaded and stored.
Browse files Browse the repository at this point in the history
  • Loading branch information
eeckstein committed Feb 15, 2016
1 parent 2c0fd72 commit c3321f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
}
void checkLoadInst(LoadInst *LI) {
require(LI->getType().isObject(), "Result of load must be an object");
require(LI->getType().isLoadable(LI->getModule()),
"Load must have a loadable type");
require(LI->getOperand()->getType().isAddress(),
"Load operand must be an address");
require(LI->getOperand()->getType().getObjectType() == LI->getType(),
Expand All @@ -949,6 +951,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
void checkStoreInst(StoreInst *SI) {
require(SI->getSrc()->getType().isObject(),
"Can't store from an address source");
require(SI->getSrc()->getType().isLoadable(SI->getModule()),
"Can't store a non loadable type");
require(SI->getDest()->getType().isAddress(),
"Must store to an address dest");
require(SI->getDest()->getType().getObjectType() == SI->getSrc()->getType(),
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/definite_init.sil
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ bb0:
%c = mark_uninitialized [var] %ba : $*@sil_weak Optional<SomeClass> // expected-note {{variable defined here}}

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

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

Expand Down
6 changes: 3 additions & 3 deletions test/SILOptimizer/existential_type_propagation.sil
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ bb2:
// CHECK: open_existential_addr
// CHECK-NEXT: witness_method
// CHECK-NEXT: apply
sil @existential_is_overwritten_by_store : $@convention(thin) (P) -> Int64 {
bb0(%0 : $P):
sil @existential_is_overwritten_by_store : $@convention(thin) (@in P) -> Int64 {
bb0(%0 : $*P):
%2 = alloc_stack $P, let, name "p"
%3 = init_existential_addr %2 : $*P, $X
%6 = integer_literal $Builtin.Int64, 27
%7 = struct $Int64 (%6 : $Builtin.Int64)
%8 = struct $X (%7 : $Int64)
store %8 to %3 : $*X
destroy_addr %2 : $*P
store %0 to %2 : $*P
copy_addr [take] %0 to %2 : $*P // id: %5
%10 = open_existential_addr %2 : $*P to $*@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P
%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
%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
Expand Down

0 comments on commit c3321f4

Please sign in to comment.