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

[WIP] Revamp LLVM error messages using annotations #441

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove the use of the WithAssertion expression from crucible-jvm
  • Loading branch information
robdockins committed Feb 13, 2020
commit 4354198d750c1ce38d7d20cbcf62ca10c94a8ee5
20 changes: 16 additions & 4 deletions crucible-jvm/src/Lang/Crucible/JVM/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,21 @@ popType2 =
iPop :: JVMStmtGen s ret (JVMInt s)
iPop = popValue >>= lift . fromIValue

iPopNonzero :: JVMStmtGen s ret (JVMInt s)
iPopNonzero =
do v <- iPop
lift $ assertExpr (App (BVNonzero knownNat v)) "java/lang/ArithmeticException"
return v

lPop :: JVMStmtGen s ret (JVMLong s)
lPop = popValue >>= lift . fromLValue

lPopNonzero :: JVMStmtGen s ret (JVMLong s)
lPopNonzero =
do v <- lPop
lift $ assertExpr (App (BVNonzero knownNat v)) "java/lang/ArithmeticException"
return v

rPop :: HasCallStack => JVMStmtGen s ret (JVMRef s)
rPop = popValue >>= lift . fromRValue

Expand Down Expand Up @@ -638,8 +650,8 @@ generateInstruction (pc, instr) =
J.Iadd -> binary iPop iPop iPush iAdd
J.Isub -> binary iPop iPop iPush iSub
J.Imul -> binary iPop iPop iPush iMul
J.Idiv -> binary iPop iPop iPush iDiv
J.Irem -> binary iPop iPop iPush iRem
J.Idiv -> binary iPop iPopNonzero iPush iDiv
J.Irem -> binary iPop iPopNonzero iPush iRem
J.Ineg -> unary iPop iPush iNeg
J.Iand -> binary iPop iPop iPush iAnd
J.Ior -> binary iPop iPop iPush iOr
Expand All @@ -651,8 +663,8 @@ generateInstruction (pc, instr) =
J.Lsub -> binary lPop lPop lPush lSub
J.Lmul -> binary lPop lPop lPush lMul
J.Lneg -> unary lPop lPush lNeg
J.Ldiv -> binary lPop lPop lPush lDiv
J.Lrem -> binary lPop lPop lPush lRem
J.Ldiv -> binary lPop lPopNonzero lPush lDiv
J.Lrem -> binary lPop lPopNonzero lPush lRem
J.Land -> binary lPop lPop lPush lAnd
J.Lor -> binary lPop lPop lPush lOr
J.Lxor -> binary lPop lPop lPush lXor
Expand Down
26 changes: 4 additions & 22 deletions crucible-jvm/src/Lang/Crucible/JVM/Translation/Numeric.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ iSub e1 e2 = App (BVSub w32 e1 e2)
iMul e1 e2 = App (BVMul w32 e1 e2)

iDiv, iRem :: JVMInt s -> JVMInt s -> JVMInt s
iDiv e1 e2 = assertNonzero w32 e2 (App (BVSdiv w32 e1 e2))
iRem e1 e2 = assertNonzero w32 e2 (App (BVSrem w32 e1 e2))
iDiv e1 e2 = App (BVSdiv w32 e1 e2)
iRem e1 e2 = App (BVSrem w32 e1 e2)

iAnd, iOr, iXor :: JVMInt s -> JVMInt s -> JVMInt s
iAnd e1 e2 = App (BVAnd w32 e1 e2)
Expand Down Expand Up @@ -123,8 +123,8 @@ lSub e1 e2 = App (BVSub w64 e1 e2)
lMul e1 e2 = App (BVMul w64 e1 e2)

lDiv, lRem :: JVMLong s -> JVMLong s -> JVMLong s
lDiv e1 e2 = assertNonzero w64 e2 (App (BVSdiv w64 e1 e2))
lRem e1 e2 = assertNonzero w64 e2 (App (BVSrem w64 e1 e2))
lDiv e1 e2 = App (BVSdiv w64 e1 e2)
lRem e1 e2 = App (BVSrem w64 e1 e2)

lAnd, lOr, lXor :: JVMLong s -> JVMLong s -> JVMLong s
lAnd e1 e2 = App (BVAnd w64 e1 e2)
Expand Down Expand Up @@ -244,21 +244,3 @@ dCmpl e1 e2 =
iIte (App (FloatFpEq e1 e2)) (iConst 0) $
iConst (-1)

----------------------------------------------------------------------
-- * Miscellaneous

-- | Assert that the first argument is nonzero.
assertNonzero ::
(1 <= n) =>
NatRepr n ->
Expr JVM s (BVType n) ->
Expr JVM s (BVType n) ->
Expr JVM s (BVType n)
assertNonzero w b expr = App (WithAssertion (BVRepr w) partExpr)
where
assertion =
JVMAssertionClassifier
["java", "lang", "ArithmeticException"]
(App (BVNonzero w b))
partExpr =
PartialExp (W4AT.Leaf assertion) expr