Skip to content

Commit

Permalink
More typechecking for ghost variables
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Sep 27, 2019
1 parent 9de5ec1 commit 2ea54c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit 2ea54c5

Please sign in to comment.