Skip to content

Commit 60f3d82

Browse files
author
Brian Huffman
committed
Make crucible_llvm_unsafe_assume_spec check function argument types.
The checking of argument types has been moved from `resolveArguments` into a separate function `checkSpecArgumentTypes`, which is called from both `crucible_llvm_verify` and `crucible_llvm_unsafe_assume_spec`. Fixes #707.
1 parent eab37ad commit 60f3d82

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

src/SAWScript/Crucible/LLVM/Builtins.hs

+39-15
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ withMethodSpec bic opts lm nm setup action =
452452
view Setup.csMethodSpec <$>
453453
execStateT (runLLVMCrucibleSetupM setup) st0
454454

455-
void $ io $ checkSpecReturnType cc methodSpec
455+
io $ checkSpecArgumentTypes cc methodSpec
456+
io $ checkSpecReturnType cc methodSpec
456457

457458
action cc methodSpec
458459

@@ -562,7 +563,43 @@ verifyObligations cc mspec tactic assumes asserts =
562563
throwMethodSpec :: MS.CrucibleMethodSpecIR (LLVM arch) -> String -> IO a
563564
throwMethodSpec mspec msg = X.throw $ LLVMMethodSpecException (mspec ^. MS.csLoc) msg
564565

565-
-- | Check that the specified return value has the expected type
566+
-- | Check that the specified arguments have the expected types.
567+
--
568+
-- The expected types are inferred from the LLVM module.
569+
checkSpecArgumentTypes ::
570+
Crucible.HasPtrWidth (Crucible.ArchWidth arch) =>
571+
LLVMCrucibleContext arch ->
572+
MS.CrucibleMethodSpecIR (LLVM arch) ->
573+
IO ()
574+
checkSpecArgumentTypes cc mspec = mapM_ resolveArg [0..(nArgs-1)]
575+
where
576+
nArgs = toInteger (length (mspec ^. MS.csArgs))
577+
tyenv = MS.csAllocations mspec
578+
nameEnv = mspec ^. MS.csPreState . MS.csVarTypeNames
579+
nm = mspec^.csName
580+
581+
checkArgTy i mt mt' =
582+
do b <- checkRegisterCompatibility mt mt'
583+
unless b $
584+
throwMethodSpec mspec $ unlines
585+
[ "Type mismatch in argument " ++ show i ++ " when verifying " ++ show nm
586+
, "Argument is declared with type: " ++ show mt
587+
, "but provided argument has incompatible type: " ++ show mt'
588+
, "Note: this may be because the signature of your " ++
589+
"function changed during compilation. If using " ++
590+
"Clang, check the signature in the disassembled " ++
591+
".ll file."
592+
]
593+
resolveArg i =
594+
case Map.lookup i (mspec ^. MS.csArgBindings) of
595+
Just (mt, sv) -> do
596+
mt' <- typeOfSetupValue cc tyenv nameEnv sv
597+
checkArgTy i mt mt'
598+
Nothing -> throwMethodSpec mspec $ unwords
599+
["Argument", show i, "unspecified when verifying", show nm]
600+
601+
602+
-- | Check that the specified return value has the expected type.
566603
--
567604
-- The expected type is inferred from the LLVM module.
568605
--
@@ -678,23 +715,10 @@ resolveArguments cc mem mspec env = mapM resolveArg [0..(nArgs-1)]
678715
nameEnv = mspec ^. MS.csPreState . MS.csVarTypeNames
679716
nm = mspec^.csName
680717

681-
checkArgTy i mt mt' =
682-
do b <- checkRegisterCompatibility mt mt'
683-
unless b $
684-
throwMethodSpec mspec $ unlines
685-
[ "Type mismatch in argument " ++ show i ++ " when veriyfing " ++ show nm
686-
, "Argument is declared with type: " ++ show mt
687-
, "but provided argument has incompatible type: " ++ show mt'
688-
, "Note: this may be because the signature of your " ++
689-
"function changed during compilation. If using " ++
690-
"Clang, check the signature in the disassembled " ++
691-
".ll file."
692-
]
693718
resolveArg i =
694719
case Map.lookup i (mspec ^. MS.csArgBindings) of
695720
Just (mt, sv) -> do
696721
mt' <- typeOfSetupValue cc tyenv nameEnv sv
697-
checkArgTy i mt mt'
698722
v <- resolveSetupVal cc mem env tyenv nameEnv sv
699723
return (mt, v)
700724
Nothing -> throwMethodSpec mspec $ unwords

0 commit comments

Comments
 (0)