Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More typechecking for ghost variables #550

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion intTests/test_ghost_types_00/test.saw
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ let main : TopLevel () = do {
f_ov <- crucible_llvm_unsafe_assume_spec m "f" (f_spec x);
// This spec should probably use a different variable, but doesn't:
g_ov <- crucible_llvm_unsafe_assume_spec m "g" (g_spec x);
crucible_llvm_verify m "h" [f_ov, g_ov] false h_spec z3;
fails (crucible_llvm_verify m "h" [f_ov, g_ov] false h_spec z3);
print "done";
};
1 change: 1 addition & 0 deletions src/SAWScript/Crucible/JVM/Override.hs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ valueToSC _sym loc failMsg _tval _val =

------------------------------------------------------------------------

-- | NOTE: The two 'Term' arguments must have the same type.
matchTerm ::
SharedContext {- ^ context for constructing SAW terms -} ->
JVMCrucibleContext {- ^ context for interacting with Crucible -} ->
Expand Down
10 changes: 9 additions & 1 deletion src/SAWScript/Crucible/LLVM/MethodSpecIR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Stability : provisional
module SAWScript.Crucible.LLVM.MethodSpecIR where

import Control.Lens
import Control.Monad (when)
import Data.Functor.Compose (Compose(..))
import Data.IORef
import Data.Monoid ((<>))
Expand All @@ -41,6 +42,8 @@ import qualified Text.LLVM.PP as L
import qualified Text.PrettyPrint.ANSI.Leijen as PPL hiding ((<$>), (<>))
import qualified Text.PrettyPrint.HughesPJ as PP

import qualified Cryptol.Utils.PP as Cryptol (pp)

import Data.Parameterized.All (All(All))
import Data.Parameterized.Some (Some(Some))
import qualified Data.Parameterized.Map as MapF
Expand Down Expand Up @@ -185,7 +188,12 @@ showLLVMModule (LLVMModule name m _) =
instance Crucible.IntrinsicClass (Crucible.SAWCoreBackend n solver (B.Flags B.FloatReal)) MS.GhostValue where
type Intrinsic (Crucible.SAWCoreBackend n solver (B.Flags B.FloatReal)) MS.GhostValue ctx = TypedTerm
muxIntrinsic sym _ _namerep _ctx prd thn els =
do st <- readIORef (B.sbStateManager sym)
do when (ttSchema thn /= ttSchema els) $ fail $ unlines $
[ "Attempted to mux ghost variables of different types:"
, show (Cryptol.pp (ttSchema thn))
, show (Cryptol.pp (ttSchema els))
]
st <- readIORef (B.sbStateManager sym)
let sc = Crucible.saw_ctx st
prd' <- Crucible.toSC sym prd
typ <- scTypeOf sc (ttTerm thn)
Expand Down
7 changes: 7 additions & 0 deletions src/SAWScript/Crucible/LLVM/Override.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import qualified Text.LLVM.AST as L

import qualified Cryptol.TypeCheck.AST as Cryptol (Schema(..))
import qualified Cryptol.Eval.Type as Cryptol (TValue(..), evalType)
import qualified Cryptol.Utils.PP as Cryptol (pp)

import qualified Lang.Crucible.Backend as Crucible
import qualified Lang.Crucible.Backend.SAWCore as Crucible
Expand Down Expand Up @@ -1025,6 +1026,7 @@ typeToSC sc t =

------------------------------------------------------------------------

-- | NOTE: The two 'Term' arguments must have the same type.
matchTerm ::
SharedContext {- ^ context for constructing SAW terms -} ->
LLVMCrucibleContext arch {- ^ context for interacting with Crucible -} ->
Expand Down Expand Up @@ -1086,6 +1088,11 @@ learnGhost ::
OverrideMatcher (LLVM arch) md ()
learnGhost sc cc loc prepost var expected =
do actual <- readGlobal var
when (ttSchema actual /= ttSchema expected) $ fail $ unlines $
[ "Ghost variable had the wrong type:"
, "- Expected: " ++ show (Cryptol.pp (ttSchema expected))
, "- Actual: " ++ show (Cryptol.pp (ttSchema actual))
]
matchTerm sc cc loc prepost (ttTerm actual) (ttTerm expected)

------------------------------------------------------------------------
Expand Down