Skip to content

Commit 6adf6f1

Browse files
author
Aaron Tomb
authored
Check bitvector types in crucible_llvm_extract (#567)
Because `crucible-llvm` merges integer and pointer types, it is not sufficient to look at Crucible types to determine whether a CFG coming from LLVM takes pointer arguments or returns a pointer. Instead, we have to look at the original LLVM types. This commit does that, and produces an error if `crucible_llvm_extract` is used with a function that has poiinter types anywhere in its signature. Fixes #521.
1 parent f3badd0 commit 6adf6f1

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

intTests/test_issue521/ptr.bc

2.11 KB
Binary file not shown.

intTests/test_issue521/ptr.c

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
unsigned int add(unsigned int *x, unsigned int *y) {
2+
return *x + *y;
3+
}

intTests/test_issue521/test.saw

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
m <- llvm_load_module "ptr.bc";
2+
fails (crucible_llvm_extract m "add");

intTests/test_issue521/test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
$SAW test.saw

src/SAWScript/Crucible/LLVM/Builtins.hs

+12-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import Control.Monad.State hiding (fail)
6464
import Control.Monad.Fail (MonadFail(..))
6565
import qualified Data.Bimap as Bimap
6666
import Data.Char (isDigit)
67-
import Data.Foldable (for_, toList, find)
67+
import Data.Foldable (for_, toList, find, fold)
6868
import Data.Function
6969
import Data.IORef
7070
import Data.List
@@ -1103,6 +1103,17 @@ crucible_llvm_extract ::
11031103
crucible_llvm_extract bic opts (Some lm) fn_name = do
11041104
let ctx = lm ^. modTrans . Crucible.transContext
11051105
let ?lc = ctx^.Crucible.llvmTypeCtx
1106+
let edef = findDefMaybeStatic (lm ^. modAST) fn_name
1107+
case edef of
1108+
Right defs -> do
1109+
let defTypes = fold $
1110+
NE.map (map L.typedType . L.defArgs) defs <>
1111+
NE.map (\d -> [L.defRetType d]) defs
1112+
when (any L.isPointer defTypes) $
1113+
fail "Pointer types are not supported by `crucible_llvm_extract`."
1114+
when (any L.isAlias defTypes) $
1115+
fail "Type aliases are not supported by `crucible_llvm_extract`."
1116+
Left err -> fail (displayVerifExceptionOpts opts err)
11061117
setupLLVMCrucibleContext bic opts lm $ \cc ->
11071118
case Map.lookup (fromString fn_name) (Crucible.cfgMap (cc^.ccLLVMModuleTrans)) of
11081119
Nothing -> fail $ unwords ["function", fn_name, "not found"]

0 commit comments

Comments
 (0)