GaloisInc / saw-script

The SAW scripting language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`saw-core-what4`: `arrayUpdate` panics when sequence literal passed as argument

qsctr opened this issue · comments

void f() {}
void g() {
    f();
}
enable_experimental;

ghost <- llvm_declare_ghost_state "ghost";

let f_spec = do {
    arr <- llvm_fresh_cryptol_var "arr" {| Array [16] [1] |};
    llvm_ghost_value ghost arr;
    llvm_execute_func [];
    llvm_ghost_value ghost {{ arrayUpdate arr 10 [True] }};
};

let g_spec = do {
    arr <- llvm_fresh_cryptol_var "arr" {| Array [16] [1] |};
    llvm_ghost_value ghost arr;
    llvm_execute_func [];
    llvm_ghost_value ghost {{ arrayUpdate arr 10 0b1 }};
};

m <- llvm_load_module "test.bc";

f_ov <- llvm_unsafe_assume_spec m "f" f_spec;
llvm_verify m "g" [f_ov] false g_spec (w4_unint_z3 []);

results in

[05:38:02.513] You have encountered a bug in SAWCoreWhat4's implementation.
*** Please create an issue at https://github.com/GaloisInc/saw-core-what4/issues

%< --------------------------------------------------- 
  Revision:  UNKNOWN
  Branch:    UNKNOWN
  Location:  Verifier.SAW.Simulator.What4.Panic.arrayUpdate
  Message:   argument type mismatch
CallStack (from HasCallStack):
  panic, called at src/Verifier/SAW/Simulator/What4/Panic.hs:14:9 in saw-core-what4-0.2-b015de163453bf1b2a579bb622b3eb875ddd7cd32e540a076c121c0f61e6595d:Verifier.SAW.Simulator.What4.Panic
  panic, called at src/Verifier/SAW/Simulator/What4.hs:663:5 in saw-core-what4-0.2-b015de163453bf1b2a579bb622b3eb875ddd7cd32e540a076c121c0f61e6595d:Verifier.SAW.Simulator.What4
%< --------------------------------------------------- 

but if you change the [True] to 0b1 then it works.

After some debugging it seems that Just (Some elm_expr) <- valueToSymExpr elm is failing due to it returning Nothing.

arrayUpdate ::
W.IsSymExprBuilder sym =>
sym ->
SArray sym ->
SValue sym ->
SValue sym ->
IO (SArray sym)
arrayUpdate sym arr idx elm
| SArray arr_expr <- arr
, Just (Some idx_expr) <- valueToSymExpr idx
, Just (Some elm_expr) <- valueToSymExpr elm
, W.BaseArrayRepr (Ctx.Empty Ctx.:> idx_repr) elm_repr <- W.exprType arr_expr
, Just Refl <- testEquality idx_repr (W.exprType idx_expr)
, Just Refl <- testEquality elm_repr (W.exprType elm_expr) =
SArray <$> W.arrayUpdate sym arr_expr (Ctx.Empty Ctx.:> idx_expr) elm_expr
| otherwise =
panic "Verifier.SAW.Simulator.What4.Panic.arrayUpdate" ["argument type mismatch"]

This is closely related to #1988, although this time, we're likely dealing with a different SAWCore data type.