@@ -452,7 +452,8 @@ withMethodSpec bic opts lm nm setup action =
452
452
view Setup. csMethodSpec <$>
453
453
execStateT (runLLVMCrucibleSetupM setup) st0
454
454
455
- void $ io $ checkSpecReturnType cc methodSpec
455
+ io $ checkSpecArgumentTypes cc methodSpec
456
+ io $ checkSpecReturnType cc methodSpec
456
457
457
458
action cc methodSpec
458
459
@@ -562,7 +563,43 @@ verifyObligations cc mspec tactic assumes asserts =
562
563
throwMethodSpec :: MS. CrucibleMethodSpecIR (LLVM arch ) -> String -> IO a
563
564
throwMethodSpec mspec msg = X. throw $ LLVMMethodSpecException (mspec ^. MS. csLoc) msg
564
565
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.
566
603
--
567
604
-- The expected type is inferred from the LLVM module.
568
605
--
@@ -678,23 +715,10 @@ resolveArguments cc mem mspec env = mapM resolveArg [0..(nArgs-1)]
678
715
nameEnv = mspec ^. MS. csPreState . MS. csVarTypeNames
679
716
nm = mspec^. csName
680
717
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
- ]
693
718
resolveArg i =
694
719
case Map. lookup i (mspec ^. MS. csArgBindings) of
695
720
Just (mt, sv) -> do
696
721
mt' <- typeOfSetupValue cc tyenv nameEnv sv
697
- checkArgTy i mt mt'
698
722
v <- resolveSetupVal cc mem env tyenv nameEnv sv
699
723
return (mt, v)
700
724
Nothing -> throwMethodSpec mspec $ unwords
0 commit comments