Skip to content

Commit 7f8ff8b

Browse files
author
Brian Huffman
committed
Implement type checking for jvm_return.
This fixes more remaining known false positives of #938.
1 parent 605abd3 commit 7f8ff8b

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

intTests/test_jvm_setup_errors/test.saw

+5-5
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ check_fails test "set"
429429
};
430430

431431
print "jvm_return with non-monomorphic type";
432-
KNOWN_FALSE_POSITIVE test "get"
432+
check_fails test "get"
433433
do {
434434
this <- jvm_alloc_object "Test";
435435
val <- jvm_fresh_var "val" java_long;
@@ -439,7 +439,7 @@ KNOWN_FALSE_POSITIVE test "get"
439439
};
440440

441441
print "jvm_return with non-jvm type";
442-
KNOWN_FALSE_POSITIVE test "get"
442+
check_fails test "get"
443443
do {
444444
this <- jvm_alloc_object "Test";
445445
val <- jvm_fresh_var "val" java_long;
@@ -449,7 +449,7 @@ KNOWN_FALSE_POSITIVE test "get"
449449
};
450450

451451
print "jvm_return with wrong base type";
452-
KNOWN_FALSE_POSITIVE test "get"
452+
check_fails test "get"
453453
do {
454454
this <- jvm_alloc_object "Test";
455455
val <- jvm_fresh_var "val" java_long;
@@ -459,7 +459,7 @@ KNOWN_FALSE_POSITIVE test "get"
459459
};
460460

461461
print "jvm_return with reference type when base type was expected";
462-
KNOWN_FALSE_POSITIVE test "get"
462+
check_fails test "get"
463463
do {
464464
this <- jvm_alloc_object "Test";
465465
val <- jvm_fresh_var "val" java_long;
@@ -478,7 +478,7 @@ KNOWN_FALSE_POSITIVE test "get"
478478
};
479479

480480
print "jvm_return when none was expected";
481-
KNOWN_FALSE_POSITIVE test "set"
481+
check_fails test "set"
482482
do {
483483
this <- jvm_alloc_object "Test";
484484
x <- jvm_fresh_var "x" java_long;

src/SAWScript/Crucible/JVM/Builtins.hs

+28-1
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,8 @@ data JVMSetupError
810810
| JVMArrayMultiple SetupValue
811811
| JVMArgTypeMismatch Int J.Type J.Type -- argument position, expected, found
812812
| JVMArgNumberWrong Int Int -- number expected, number found
813+
| JVMReturnUnexpected J.Type -- found
814+
| JVMReturnTypeMismatch J.Type J.Type -- expected, found
813815

814816
instance X.Exception JVMSetupError
815817

@@ -885,6 +887,17 @@ instance Show JVMSetupError where
885887
, "Expected: " ++ show expected
886888
, "Given: " ++ show found
887889
]
890+
JVMReturnUnexpected found ->
891+
unlines
892+
[ "jvm_return: Unexpected return value for void method"
893+
, "Given type: " ++ show found
894+
]
895+
JVMReturnTypeMismatch expected found ->
896+
unlines
897+
[ "jvm_return: Return type mismatch"
898+
, "Expected type: " ++ show expected
899+
, "Given type: " ++ show found
900+
]
888901

889902
-- | Returns Cryptol type of actual type if it is an array or
890903
-- primitive type.
@@ -1101,7 +1114,21 @@ jvm_execute_func bic opts args =
11011114
Setup.crucible_execute_func bic opts args
11021115

11031116
jvm_return :: BuiltinContext -> Options -> SetupValue -> JVMSetupM ()
1104-
jvm_return bic opts retVal = JVMSetupM $ Setup.crucible_return bic opts retVal
1117+
jvm_return bic opts retVal =
1118+
JVMSetupM $
1119+
do st <- get
1120+
let cc = st ^. Setup.csCrucibleContext
1121+
let mspec = st ^. Setup.csMethodSpec
1122+
let env = MS.csAllocations mspec
1123+
let nameEnv = MS.csTypeNames mspec
1124+
valTy <- typeOfSetupValue cc env nameEnv retVal
1125+
case mspec ^. MS.csRet of
1126+
Nothing ->
1127+
X.throwM (JVMReturnUnexpected valTy)
1128+
Just retTy ->
1129+
unless (registerCompatible retTy valTy) $
1130+
X.throwM (JVMReturnTypeMismatch retTy valTy)
1131+
Setup.crucible_return bic opts retVal
11051132

11061133
--------------------------------------------------------------------------------
11071134

0 commit comments

Comments
 (0)