You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/analyses/assert.ml
+9-21Lines changed: 9 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -14,36 +14,24 @@ struct
14
14
(* transfer functions *)
15
15
16
16
letassert_fnmanecheckrefine=
17
-
let expr =CilType.Exp.show e in
18
-
letwarnwarn_fn?annotmsg=if check then
19
-
if get_bool "dbg.regression"then ( (* This only prints unexpected results (with the difference) as indicated by the comment behind the assert (same as used by the regression test script). *)
20
-
let loc =!M.current_loc in
21
-
let line =List.at (List.of_enum @@File.lines_of loc.file) (loc.line-1) in(* nosemgrep: batenum-of_enum *)
22
-
letopenStrin
23
-
let expected =if string_match (regexp ".+//.*\\(FAIL\\|UNKNOWN\\).*") line 0thenSome (matched_group 1 line) elseNonein
24
-
if expected <> annot then (
25
-
let result =if annot =None&& (expected =Some ("NOWARN") || (expected =Some ("UNKNOWN") &¬ (String.exists line "UNKNOWN!"))) then"improved"else"failed"in
26
-
(* Expressions with logical connectives like a && b are calculated in temporary variables by CIL. Instead of the original expression, we then see something like tmp___0. So we replace expr in msg by the original source if this is the case. *)
27
-
let assert_expr =if string_match (regexp ".*assert(\\(.+\\));.*") line 0then matched_group 1 line else expr in
28
-
let msg =if expr <> assert_expr thenString.nreplace ~str:msg ~sub:expr ~by:assert_expr else msg in
(* TODO: use format instead of %s for the following messages *)
35
23
matchQueries.eval_bool (Analyses.ask_of_man man) e with
36
24
|`Liftedfalse ->
37
-
warn (M.error ~category:Assert"%s") ~annot:"FAIL" ("Assertion \""^ expr ^"\" will fail.");
25
+
assert_msg Error"Assertion \"%a\" will fail."CilType.Exp.pretty e;
38
26
if refine then raise Analyses.Deadcodeelse man.local
39
27
|`Liftedtrue ->
40
-
warn (M.success ~category:Assert"%s") ("Assertion \""^ expr ^"\" will succeed");
28
+
assert_msg Success"Assertion \"%a\" will succeed"CilType.Exp.pretty e;
41
29
man.local
42
30
|`Bot ->
43
-
M.error ~category:Assert"%s" ("Assertion \""^ expr ^"\" produces a bottom. What does that mean? (currently uninitialized arrays' content is bottom)");
31
+
M.error ~category:Assert"Assertion \"%a\" produces a bottom. What does that mean? (currently uninitialized arrays' content is bottom)"CilType.Exp.pretty e;
44
32
man.local
45
33
|`Top ->
46
-
warn (M.warn ~category:Assert"%s") ~annot:"UNKNOWN" ("Assertion \""^ expr ^"\" is unknown.");
34
+
assert_msg Warning"Assertion \"%a\" is unknown."CilType.Exp.pretty e;
0 commit comments