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

Structured assertions #151

Merged
merged 60 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
672ffee
[WIP]: PartLLVMVal refactor
langston-barrett Jan 16, 2019
d783edf
[WIP] More partial value refactor: the code compiles! (readMemSet')
langston-barrett Jan 16, 2019
a84e130
[WIP] all readMem* functions
langston-barrett Jan 18, 2019
0dd76bb
Simplifying and pretty-printing PartLLVMVal'
langston-barrett Jan 24, 2019
887d434
Start putting stuff in Crucible and What4
langston-barrett Jan 25, 2019
67a9979
HasSafetyAssertions
langston-barrett Jan 25, 2019
4a7e188
Start folding in new Crucible SafetyAssertion stuff in crucible-llvm
langston-barrett Jan 25, 2019
395dddb
Hold structured, relevant information in UB and Poison constructors
langston-barrett Jan 25, 2019
621e23b
remove old-style partllvmval functions
langston-barrett Jan 25, 2019
97e2741
a few more operations
langston-barrett Jan 25, 2019
21be286
what4: add second type parameter to AssertionTree
langston-barrett Jan 26, 2019
88f604c
No more type errors in MemModel.Generic
langston-barrett Jan 26, 2019
f49ef41
fewer type errors in MemModel.hs
langston-barrett Jan 26, 2019
e53cf2d
Add appropriate arguments to Poison constructors
langston-barrett Jan 28, 2019
f14732c
[WIP]
langston-barrett Jan 30, 2019
626b882
Fix rebase mistakes
langston-barrett Jan 30, 2019
eef5c75
Complete implementation of SafetyAssertion family in Crucible
langston-barrett Jan 31, 2019
329f110
crucible: More specific imports
langston-barrett Jan 31, 2019
e433311
remove accidentally-committed files
langston-barrett Jan 31, 2019
c2248a0
Progress on porting crucible-llvm to structured assertions
langston-barrett Jan 31, 2019
d9eda84
explainTree and assertSafe
langston-barrett Feb 1, 2019
6ccc738
testequality bug
langston-barrett Feb 1, 2019
8504882
OrdF -> OrdC
langston-barrett Feb 2, 2019
40b24b3
instance TestEqualityC Poison
langston-barrett Feb 2, 2019
a4b1b46
change kind of SafetyAssertion
langston-barrett Feb 4, 2019
3230581
Finish changing the kind of SafetyAssertion
langston-barrett Feb 4, 2019
7ce2c12
Approach based on AssertionClassifier and PartialExpr
langston-barrett Feb 4, 2019
4d907a5
Use *C classes again, port crucible-llvm to new stuff
langston-barrett Feb 5, 2019
b665ecd
progress on aspects of crucible-llvm
langston-barrett Feb 5, 2019
6994e6a
Finish up Instruction
langston-barrett Feb 5, 2019
a805739
AssertionTree instances: Eq1, Eq2, .., Ord2, Bifunctor, Bitraversable
langston-barrett Feb 5, 2019
ac69598
some Template Haskell *(F|C) instances
langston-barrett Feb 6, 2019
98812eb
even more TH instances
langston-barrett Feb 6, 2019
fc77f59
evaluation of withassertion
langston-barrett Feb 6, 2019
98b12c1
Complete OrdFC instance for PartialExpr
langston-barrett Feb 6, 2019
29d8959
llvm HasStructuredAssertions instance
langston-barrett Feb 6, 2019
a7a6460
Clean up imports/exports in LLVM.Extension
langston-barrett Feb 6, 2019
b932d87
general cleanup
langston-barrett Feb 7, 2019
56be0c1
crucible-jvm: structured assertions
langston-barrett Feb 7, 2019
e3de18b
Fix haddock comments on GADT constructors
langston-barrett Feb 7, 2019
fbd050e
Fix one more GADT constructor's haddock
langston-barrett Feb 7, 2019
eb356e8
Fix `undefined` and incomplete pattern match
langston-barrett Feb 8, 2019
9471aaf
fix typo
langston-barrett Feb 8, 2019
28b1692
Standards.hs is Safe Haskell
langston-barrett Feb 8, 2019
ca064ff
Remove UndefinedBehavior.Config
langston-barrett Feb 8, 2019
4db0cca
Remove old code wrapped in a block comment
langston-barrett Feb 8, 2019
78b071c
Merge branch 'master' into HEAD
robdockins Feb 8, 2019
8bfcdb1
bump submodule
robdockins Feb 8, 2019
b0b94a0
Fixup merge
robdockins Feb 8, 2019
d51693c
Introduce the Partial type, reorganize What4.Partial
langston-barrett Feb 8, 2019
724fec5
What4: merge Partial and PartExpr into one module/representation
langston-barrett Feb 8, 2019
f58a070
crucible: fix partexpr imports
langston-barrett Feb 8, 2019
9b55c2a
Merge remote-tracking branch 'upstream/partllvmval' into partllvmval-…
langston-barrett Feb 8, 2019
5520636
Remove ubiquitous PartLLVMVal suffices from functions
langston-barrett Feb 8, 2019
c03edc6
MemoryModel.Partial: more structured type errors
langston-barrett Feb 8, 2019
7f0b7f8
propagate structured errors through memory model operations
langston-barrett Feb 9, 2019
644c5bc
more progress on `merge`
langston-barrett Feb 9, 2019
02a4db1
update crucible-jvm
langston-barrett Feb 11, 2019
64dfa14
Merge remote-tracking branch 'upstream/master' into partllvmval-rebased
langston-barrett Feb 13, 2019
ac97d5d
Merge remote-tracking branch 'upstream/master' into partllvmval-rebased
langston-barrett Mar 4, 2019
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
67 changes: 35 additions & 32 deletions crucible-jvm/src/Lang/Crucible/JVM/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ module Lang.Crucible.JVM.Translation
where

-- base
import Data.Maybe (maybeToList)
import Data.Semigroup(Semigroup(..),(<>))
import Control.Monad.State.Strict
import Control.Monad.ST
import Control.Lens hiding (op, (:>))
import Data.Int (Int32)
import Data.Map.Strict (Map)
import Data.Maybe (maybeToList)
import Data.Semigroup (Semigroup(..),(<>))
import Control.Monad.State.Strict
import Control.Monad.ST
import Control.Lens hiding (op, (:>))
import Data.Int (Int32)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.String (fromString)
import Data.List (isPrefixOf)
import Data.String (fromString)
import Data.List (isPrefixOf)

import System.IO
import System.IO

-- jvm-parser
import qualified Language.JVM.Common as J
Expand All @@ -70,6 +70,7 @@ import Data.Parameterized.NatRepr as NR
import qualified Lang.Crucible.CFG.Core as C
import Lang.Crucible.CFG.Expr
import Lang.Crucible.CFG.Generator
import Lang.Crucible.CFG.Extension.Safety (pattern PartialExp)
import Lang.Crucible.CFG.SSAConversion (toSSA)
import Lang.Crucible.FunctionHandle
import Lang.Crucible.Types
Expand All @@ -78,17 +79,18 @@ import Lang.Crucible.Panic

import Lang.Crucible.Utils.MonadVerbosity

import qualified Lang.Crucible.Simulator as C
import qualified Lang.Crucible.Simulator.GlobalState as C
import qualified Lang.Crucible.Analysis.Postdom as C
import qualified Lang.Crucible.Simulator.CallFrame as C
import qualified Lang.Crucible.Simulator as C
import qualified Lang.Crucible.Simulator.GlobalState as C
import qualified Lang.Crucible.Analysis.Postdom as C
import qualified Lang.Crucible.Simulator.CallFrame as C


-- what4
import What4.ProgramLoc (Position(InternalPos))
import What4.FunctionName
import qualified What4.Interface as W4
import qualified What4.Config as W4
import qualified What4.Interface as W4
import qualified What4.Config as W4
import qualified What4.Partial.AssertionTree as W4AT

import What4.Utils.MonadST (liftST)

Expand All @@ -102,7 +104,7 @@ import Lang.Crucible.JVM.Overrides
import qualified Lang.JVM.Codebase as JCB


import Debug.Trace
import Debug.Trace

{-
This module is in two parts, the first part includes functions for translating
Expand Down Expand Up @@ -739,14 +741,8 @@ generateInstruction (pc, instr) =
J.Iadd -> binary iPop iPop iPush (\a b -> App (BVAdd w32 a b))
J.Isub -> binary iPop iPop iPush (\a b -> App (BVSub w32 a b))
J.Imul -> binary iPop iPop iPush (\a b -> App (BVMul w32 a b))
J.Idiv -> binary iPop iPop iPush
(\a b -> App (AddSideCondition (BaseBVRepr w32) (App (BVNonzero w32 b))
"java/lang/ArithmeticException"
(App (BVSdiv w32 a b))))
J.Irem -> binary iPop iPop iPush
(\a b -> App (AddSideCondition (BaseBVRepr w32) (App (BVNonzero w32 b))
"java/lang/ArithmeticException"
(App (BVSrem w32 a b))))
J.Idiv -> binary iPop iPop iPush (\a b -> nonzero w32 b (App (BVSdiv w32 a b)))
J.Irem -> binary iPop iPop iPush (\a b -> nonzero w32 b (App (BVSrem w32 a b)))
J.Ineg -> unaryGen iPop iPush iNeg
J.Iand -> binary iPop iPop iPush (\a b -> App (BVAnd w32 a b))
J.Ior -> binary iPop iPop iPush (\a b -> App (BVOr w32 a b))
Expand All @@ -761,13 +757,8 @@ generateInstruction (pc, instr) =
J.Ldiv -> binary lPop lPop lPush -- TODO: why was this lPush an error?
-- there is also a special case when when dividend is maxlong
-- and divisor is -1
(\a b -> App (AddSideCondition (BaseBVRepr w64) (App (BVNonzero w64 b))
"java/lang/ArithmeticException"
(App (BVSdiv w64 a b))))
J.Lrem -> binary lPop lPop lPush
(\a b -> App (AddSideCondition (BaseBVRepr w64) (App (BVNonzero w64 b))
"java/lang/ArithmeticException"
(App (BVSrem w64 a b))))
(\a b -> nonzero w64 b (App (BVSdiv w64 a b)))
J.Lrem -> binary lPop lPop lPush (\a b -> nonzero w64 b (App (BVSrem w64 a b)))
J.Land -> binary lPop lPop lPush (\a b -> App (BVAnd w64 a b))
J.Lor -> binary lPop lPop lPush (\a b -> App (BVOr w64 a b))
J.Lxor -> binary lPop lPop lPush (\a b -> App (BVXor w64 a b))
Expand Down Expand Up @@ -1089,6 +1080,18 @@ generateInstruction (pc, instr) =
do void rPop
J.Nop ->
do return ()
where nonzero :: (1 <= n)
=> NatRepr n
-> Expr JVM s (BVType n)
-> Expr JVM s (BVType n)
-> Expr JVM s (BVType n)

nonzero w b expr =
let assertion =
JVMAssertionClassifier ["java", "lang", "ArithmeticException"]
(App (BVNonzero w b))
partExpr = PartialExp (W4AT.Leaf assertion) expr
in App (WithAssertion (BVRepr w) partExpr)

unary ::
JVMStmtGen h s ret a ->
Expand Down
86 changes: 84 additions & 2 deletions crucible-jvm/src/Lang/Crucible/JVM/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,64 @@ License : BSD3
Maintainer : [email protected]
Stability : provisional
-}

{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE BangPatterns #-}

{-# OPTIONS_GHC -haddock #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}


module Lang.Crucible.JVM.Types where

import Prelude hiding (pred)

import GHC.Generics (Generic)
import Data.Typeable (Typeable)
import Data.Maybe (isJust)
import Data.List (intercalate)
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>))

-- jvm-parser
import qualified Language.JVM.Parser as J

-- parameterized-utils
import qualified Data.Parameterized.Context as Ctx
import Data.Parameterized.Some
import Data.Parameterized.ClassesC (TestEqualityC(..), OrdC(..))
import Data.Parameterized.TraversableF (FunctorF(..), FoldableF(..), TraversableF(..))
import qualified Data.Parameterized.TraversableF as TF
import Data.Parameterized.Classes (toOrdering)
import qualified Data.Parameterized.TH.GADT as U

-- crucible
import qualified Lang.Crucible.CFG.Core as C
import Lang.Crucible.CFG.Expr
import Lang.Crucible.Simulator.RegValue (RegValue'(unRV))
import Lang.Crucible.CFG.Generator
import qualified Lang.Crucible.CFG.Extension.Safety as Safety
import Lang.Crucible.Types

----------------------------------------------------------------------
Expand All @@ -50,11 +72,71 @@ import Lang.Crucible.Types
newtype JVM = JVM ()
type instance ExprExtension JVM = EmptyExprExtension
type instance StmtExtension JVM = EmptyStmtExtension
instance IsSyntaxExtension JVM

instance IsSyntaxExtension JVM

type Verbosity = Int

----------------------------------------------------------------------
-- * Structured assertions

data JVMAssertionClassifier (e :: CrucibleType -> *) =
JVMAssertionClassifier { exceptionClass :: [String]
-- ^ Class path of the associated exception
, pred :: e BoolType
}
deriving (Generic, Typeable)

type instance Safety.AssertionClassifier JVM = JVMAssertionClassifier

-- -----------------------------------------------------------------------
-- *** Instances

$(return [])

instance TestEqualityC JVMAssertionClassifier where
testEqualityC testSubterm (JVMAssertionClassifier cls1 pred1)
(JVMAssertionClassifier cls2 pred2) =
and [ isJust (testSubterm pred1 pred2)
, cls1 == cls2
]

instance OrdC JVMAssertionClassifier where
compareC subterms sa1 sa2 = toOrdering $
$(U.structuralTypeOrd [t|JVMAssertionClassifier|]
[ ( U.AnyType `U.TypeApp` U.DataArg 0
, [| \x y -> fromOrdering (compareC subterms x y) |]
)
, ( U.DataArg 0 `U.TypeApp` U.AnyType
, [| subterms |]
)
]
) sa1 sa2

instance FunctorF JVMAssertionClassifier where
fmapF f (JVMAssertionClassifier cls pred_) =
JVMAssertionClassifier cls (f pred_)

instance FoldableF JVMAssertionClassifier where
foldMapF = TF.foldMapFDefault

instance TraversableF JVMAssertionClassifier where
traverseF subterms=
$(U.structuralTraversal [t|JVMAssertionClassifier|]
[ ( U.AnyType `U.TypeApp` U.DataArg 0
, [| \_ -> traverseF subterms |]
)
, ( U.DataArg 0 `U.TypeApp` U.AnyType
, [| \_ -> subterms |]
)
]
) subterms

instance Safety.HasStructuredAssertions JVM where
explain _proxyExt (JVMAssertionClassifier cls _pred) =
text ("Exception of class " ++ intercalate "." cls)
toPredicate _proxyExt _sym = pure . unRV . pred

---------------------------------------------------------------------------------
-- * Type abbreviations for expressions

Expand Down
20 changes: 12 additions & 8 deletions crucible-llvm/crucible-llvm.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: crucible-llvm
Version: 0.2
Version: 0.3
Author: Galois Inc.
Copyright: (c) Galois, Inc 2014-2018
Maintainer: [email protected]
Expand All @@ -17,8 +17,7 @@ library
attoparsec,
bytestring,
containers >= 0.5.8.0,
contravariant >= 1,
crucible,
crucible >= 0.5,
what4 >= 0.4.1,
deepseq,
directory,
Expand All @@ -30,7 +29,6 @@ library
llvm-pretty >= 0.8 && < 0.11,
mtl,
parameterized-utils >= 1.0.4 && < 1.1,
template-haskell,
text,
transformers,
unordered-containers,
Expand All @@ -42,32 +40,38 @@ library
exposed-modules:
Lang.Crucible.LLVM
Lang.Crucible.LLVM.Arch
Lang.Crucible.LLVM.Arch.X86
Lang.Crucible.LLVM.Arch.Util
Lang.Crucible.LLVM.Arch.X86
Lang.Crucible.LLVM.Bytes
Lang.Crucible.LLVM.Ctors
Lang.Crucible.LLVM.DataLayout
Lang.Crucible.LLVM.Extension
Lang.Crucible.LLVM.Intrinsics
Lang.Crucible.LLVM.Extension.Safety
Lang.Crucible.LLVM.Extension.Safety.Poison
Lang.Crucible.LLVM.Extension.Safety.UndefinedBehavior
Lang.Crucible.LLVM.Globals
Lang.Crucible.LLVM.Intrinsics
Lang.Crucible.LLVM.MemModel
Lang.Crucible.LLVM.MemType
Lang.Crucible.LLVM.PrettyPrint
Lang.Crucible.LLVM.Printf
Lang.Crucible.LLVM.Translation
Lang.Crucible.LLVM.TypeContext
Lang.Crucible.LLVM.UndefinedBehavior

other-modules:
Lang.Crucible.LLVM.Extension.Arch
Lang.Crucible.LLVM.Extension.Syntax
Lang.Crucible.LLVM.Extension.Safety.Standards
Lang.Crucible.LLVM.Intrinsics.Common
Lang.Crucible.LLVM.Intrinsics.Libc
Lang.Crucible.LLVM.Intrinsics.Libcxx
Lang.Crucible.LLVM.Intrinsics.LLVM
Lang.Crucible.LLVM.MemModel.Common
Lang.Crucible.LLVM.MemModel.Generic
Lang.Crucible.LLVM.MemModel.Value
Lang.Crucible.LLVM.MemModel.Partial
Lang.Crucible.LLVM.MemModel.Pointer
Lang.Crucible.LLVM.MemModel.Type
Lang.Crucible.LLVM.MemModel.Value
Lang.Crucible.LLVM.Translation.Constant
Lang.Crucible.LLVM.Translation.Expr
Lang.Crucible.LLVM.Translation.Instruction
Expand Down
Loading