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

x86: Properly include assumed preconditions in goals #1095

Merged
merged 3 commits into from
Apr 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added intTests/test_llvm_x86_07/test
Binary file not shown.
10 changes: 10 additions & 0 deletions intTests/test_llvm_x86_07/test.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
section .bss
section .text
global precondtest
precondtest:
mov rax, rdi
ret
global _start
_start:
mov rax, 60
syscall
8 changes: 8 additions & 0 deletions intTests/test_llvm_x86_07/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdint.h>
#include <stdio.h>

extern uint64_t precondtest(uint64_t x);

void test() {
precondtest(1);
};
14 changes: 14 additions & 0 deletions intTests/test_llvm_x86_07/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enable_experimental;

m <- llvm_load_module "test.bc";

let precondtest_setup = do {
x <- crucible_fresh_var "x" (llvm_int 64);
crucible_precond {{ x < 10 }};
llvm_execute_func [crucible_term x];
x' <- crucible_fresh_var "x'" (llvm_int 64);
crucible_return (crucible_term x');
crucible_postcond {{ x' < 10 }};
};

llvm_verify_x86 m "./test" "precondtest" [] false precondtest_setup w4;
7 changes: 7 additions & 0 deletions intTests/test_llvm_x86_07/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

# yasm -felf64 test.S
# ld test.o -o test
clang -c -emit-llvm test.c
$SAW test.saw
1 change: 1 addition & 0 deletions src/SAWScript/Crucible/LLVM/Override.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module SAWScript.Crucible.LLVM.Override

, learnCond
, learnSetupCondition
, executeSetupCondition
, matchArg
, assertTermEqualities
, methodSpecHandler
Expand Down
21 changes: 18 additions & 3 deletions src/SAWScript/Crucible/LLVM/X86.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import SAWScript.X86 hiding (Options)
import SAWScript.X86Spec
import SAWScript.Crucible.Common

import qualified SAWScript.Crucible.Common as Common
import qualified SAWScript.Crucible.Common.MethodSpec as MS
import qualified SAWScript.Crucible.Common.Override as O
import qualified SAWScript.Crucible.Common.Setup.Type as Setup
Expand Down Expand Up @@ -437,7 +438,15 @@ llvm_verify_x86 (Some (llvmModule :: LLVMModule x)) path nm globsyms checkSat se

liftIO $ C.executeCrucible execFeatures initial >>= \case
C.FinishedResult{} -> pure ()
C.AbortedResult{} -> printOutLn opts Warn "Warning: function never returns"
C.AbortedResult _ ar -> do
printOutLn opts Warn "Warning: function never returns"
print $ Common.ppAbortedResult
( \gp ->
case C.lookupGlobal mvar $ gp ^. C.gpGlobals of
Nothing -> "LLVM memory global variable not initialized"
Just mem -> C.LLVM.ppMem $ C.LLVM.memImplHeap mem
)
ar
C.TimeoutResult{} -> fail "Execution timed out"

stats <- checkGoals sym opts sc tactic
Expand Down Expand Up @@ -870,7 +879,10 @@ assertPost globals env premem preregs = do
pointsToMatches <- forM (ms ^. MS.csPostState . MS.csPointsTos)
$ assertPointsTo env tyenv nameEnv

let setupConditionMatches = fmap
let setupConditionMatchesPre = fmap -- assume preconditions
(LO.executeSetupCondition opts sc cc ms)
$ ms ^. MS.csPreState . MS.csConditions
let setupConditionMatchesPost = fmap -- assert postconditions
(LO.learnSetupCondition opts sc cc ms MS.PostState)
$ ms ^. MS.csPostState . MS.csConditions

Expand All @@ -889,12 +901,15 @@ assertPost globals env premem preregs = do
. sequence_ $ mconcat
[ returnMatches
, pointsToMatches
, setupConditionMatches
, setupConditionMatchesPre
, setupConditionMatchesPost
, [LO.assertTermEqualities sc cc]
]
st <- case result of
Left err -> throwX86 $ show err
Right (_, st) -> pure st
liftIO . forM_ (view O.osAssumes st) $ \p ->
C.addAssumption sym . C.LabeledPred p $ C.AssumptionReason (st ^. O.osLocation) "precondition"
liftIO . forM_ (view LO.osAsserts st) $ \(W4.LabeledPred p r) ->
C.addAssertion sym $ C.LabeledPred p r

Expand Down