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

Catch and handle gracefully when concrete evaluation produces an error #1903

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 11 additions & 6 deletions src/SAWScript/Crucible/JVM/ResolveSetupValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module SAWScript.Crucible.JVM.ResolveSetupValue

import Control.Lens
import qualified Control.Monad.Catch as X
import Control.Exception (catch)
import qualified Data.BitVector.Sized as BV
import Data.Map (Map)
import qualified Data.Map as Map
Expand Down Expand Up @@ -265,9 +266,11 @@ resolveBitvectorTerm sym w tm =
mx <- case getAllExts tm of
-- concretely evaluate if it is a closed term
[] ->
do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
pure (Just (Prim.unsigned (Concrete.toWord v)))
catch (do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
seq v (pure (Just (Prim.unsigned (Concrete.toWord v)))))
-- return Nothing if concrete evaluation results in an error
(\(_ :: Prim.EvalError) -> return Nothing)
_ -> return Nothing
case mx of
Just x -> W4.bvLit sym w (BV.mkBV w x)
Expand All @@ -280,9 +283,11 @@ resolveBoolTerm sym tm =
mx <- case getAllExts tm of
-- concretely evaluate if it is a closed term
[] ->
do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
pure (Just (Concrete.toBool v))
catch (do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
seq v (pure (Just (Concrete.toBool v))))
-- return Nothing if concrete evaluation results in an error
(\(_ :: Prim.EvalError) -> return Nothing)
_ -> return Nothing
case mx of
Just x -> return (W4.backendPred sym x)
Expand Down
17 changes: 11 additions & 6 deletions src/SAWScript/Crucible/LLVM/ResolveSetupValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Control.Lens ( (^.), view )
import Control.Monad
import Control.Monad.Except
import Control.Monad.State
import Control.Exception (catch)
import qualified Data.BitVector.Sized as BV
import Data.Maybe (fromMaybe, fromJust)

Expand Down Expand Up @@ -734,9 +735,11 @@ resolveSAWPred cc tm = do
(_,tm') <- rewriteSharedTerm sc ss tm
mx <- case getAllExts tm' of
-- concretely evaluate if it is a closed term
[] -> do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
pure (Just (Concrete.toBool v))
[] -> catch (do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
seq v (pure (Just (Concrete.toBool v))))
-- return Nothing if concrete evaluation results in an error
(\(_ :: Prim.EvalError) -> return Nothing)
_ -> return Nothing
case mx of
Just x -> return $ W4.backendPred sym x
Expand Down Expand Up @@ -764,9 +767,11 @@ resolveSAWSymBV cc w tm =
let sc = saw_ctx st
mx <- case getAllExts tm of
-- concretely evaluate if it is a closed term
[] -> do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
pure (Just (Prim.unsigned (Concrete.toWord v)))
[] -> catch (do modmap <- scGetModuleMap sc
let v = Concrete.evalSharedTerm modmap mempty mempty tm
seq v (pure (Just (Prim.unsigned (Concrete.toWord v)))))
-- return Nothing if concrete evaluation results in an error
(\(_ :: Prim.EvalError) -> return Nothing)
_ -> return Nothing
case mx of
Just x -> W4.bvLit sym w (BV.mkBV w x)
Expand Down
Loading