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: Pass the right nameEnv in resolvePtrSetupValue #1534

Merged
merged 2 commits into from
Dec 7, 2021
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ intTests/test_intro_examples/*.cnf
intTests/test_llvm_x86_0[1234]/test
intTests/test_llvm_x86_0[1234]/test.o
intTests/test_llvm_x86_0[1234]/test.bc
intTests/test1533/test.o
intTests/test*/*.out
intTests/test_crucible_jvm/Stat.class
intTests/test_profiling/prof
Expand Down
17 changes: 17 additions & 0 deletions intTests/test1533/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CC = clang
CFLAGS = -g -frecord-command-line -O0

all: test.bc test.exe

test.bc: test.c
$(CC) $(CFLAGS) -c -emit-llvm $< -o $@

test.o: test.c
$(CC) $(CFLAGS) -c $< -o $@

test.exe: test.o
$(CC) $(CFLAGS) $< -o $@

.PHONY: clean
clean:
rm -f test.bc test.exe
Binary file added intTests/test1533/test.bc
Binary file not shown.
14 changes: 14 additions & 0 deletions intTests/test1533/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdint.h>

struct s {
uint8_t x1;
uint8_t x2;
};

uint8_t get_x2(struct s *ss) {
return ss->x2;
}

int main() {
return 0;
}
Binary file added intTests/test1533/test.exe
Binary file not shown.
14 changes: 14 additions & 0 deletions intTests/test1533/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enable_experimental;

let get_x2_spec = do {
ss <- llvm_alloc (llvm_alias "struct.s");
z <- llvm_fresh_var "z" (llvm_int 8);
llvm_points_to (llvm_field ss "x2") (llvm_term z);
llvm_execute_func [ss];
llvm_return (llvm_term z);
};

m <- llvm_load_module "test.bc";

llvm_verify m "get_x2" [] false get_x2_spec (w4_unint_z3 []);
llvm_verify_x86 m "test.exe" "get_x2" [] false get_x2_spec (w4_unint_z3 []);
5 changes: 5 additions & 0 deletions intTests/test1533/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

$SAW test.saw
15 changes: 9 additions & 6 deletions src/SAWScript/Crucible/LLVM/X86.hs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ assumePointsTo env tyenv nameEnv (LLVMPointsTo _ cond tptr tptval) = do
opts <- use x86Options
cc <- use x86CrucibleContext
mem <- use x86Mem
ptr <- resolvePtrSetupValue env tyenv tptr
ptr <- resolvePtrSetupValue env tyenv nameEnv tptr
cond' <- liftIO $ mapM (resolveSAWPred cc . ttTerm) cond
mem' <- liftIO $ LO.storePointsToValue opts cc env tyenv nameEnv mem cond' ptr tptval Nothing
x86Mem .= mem'
Expand All @@ -771,9 +771,10 @@ resolvePtrSetupValue ::
X86Constraints =>
Map MS.AllocIndex Ptr ->
Map MS.AllocIndex LLVMAllocSpec ->
Map MS.AllocIndex C.LLVM.Ident {- ^ Associates each AllocIndex with its name -} ->
MS.SetupValue LLVM ->
X86Sim Ptr
resolvePtrSetupValue env tyenv tptr = do
resolvePtrSetupValue env tyenv nameEnv tptr = do
sym <- use x86Sym
cc <- use x86CrucibleContext
mem <- use x86Mem
Expand All @@ -789,7 +790,7 @@ resolvePtrSetupValue env tyenv tptr = do
let addr = fromIntegral $ Elf.steValue entry
liftIO $ C.LLVM.doPtrAddOffset sym mem base =<< W4.bvLit sym knownNat (BV.mkBV knownNat addr)
_ -> liftIO $ C.LLVM.unpackMemValue sym (C.LLVM.LLVMPointerRepr $ knownNat @64)
=<< resolveSetupVal cc mem env tyenv Map.empty tptr
=<< resolveSetupVal cc mem env tyenv nameEnv tptr

-- | Write each SetupValue passed to llvm_execute_func to the appropriate
-- x86_64 register from the calling convention.
Expand Down Expand Up @@ -852,6 +853,7 @@ assertPost globals env premem preregs = do
postregs <- use x86Regs
let
tyenv = ms ^. MS.csPreState . MS.csAllocs
nameEnv = MS.csTypeNames ms

prersp <- getReg Macaw.RSP preregs
expectedIP <- liftIO $ C.LLVM.doLoad sym premem prersp (C.LLVM.bitvectorType 8)
Expand Down Expand Up @@ -890,7 +892,7 @@ assertPost globals env premem preregs = do


pointsToMatches <- forM (ms ^. MS.csPostState . MS.csPointsTos)
$ assertPointsTo env tyenv
$ assertPointsTo env tyenv nameEnv

let setupConditionMatchesPre = fmap -- assume preconditions
(LO.executeSetupCondition opts sc cc ms)
Expand Down Expand Up @@ -931,15 +933,16 @@ assertPointsTo ::
X86Constraints =>
Map MS.AllocIndex Ptr {- ^ Associates each AllocIndex with the corresponding allocation -} ->
Map MS.AllocIndex LLVMAllocSpec {- ^ Associates each AllocIndex with its specification -} ->
Map MS.AllocIndex C.LLVM.Ident {- ^ Associates each AllocIndex with its name -} ->
LLVMPointsTo LLVMArch {- ^ llvm_points_to statement from the precondition -} ->
X86Sim (LLVMOverrideMatcher md ())
assertPointsTo env tyenv pointsTo@(LLVMPointsTo loc cond tptr tptval) = do
assertPointsTo env tyenv nameEnv pointsTo@(LLVMPointsTo loc cond tptr tptval) = do
opts <- use x86Options
sc <- use x86SharedContext
cc <- use x86CrucibleContext
ms <- use x86MethodSpec

ptr <- resolvePtrSetupValue env tyenv tptr
ptr <- resolvePtrSetupValue env tyenv nameEnv tptr
pure $ do
err <- LO.matchPointsToValue opts sc cc ms MS.PostState loc cond ptr tptval
case err of
Expand Down