Skip to content
Snippets Groups Projects
Commit 28ad9e61 authored by Thibault Martin's avatar Thibault Martin
Browse files

[tests] Add a test for constFoldTerm

parent 8c610b56
No related branches found
No related tags found
No related merge requests found
/* run.config
MODULE: @PTEST_NAME@
STDOPT: -print
*/
void unop(int a) {
//@ assert -(21 + 21);
//@ assert ~21;
//@ assert -a;
}
void binop(int a) {
//@ assert 21 + 21 + a == 42;
//@ assert 84 - 42 == 42;
//@ assert 6 * 7 == 42;
//@ assert 21 << 1 == 42;
//@ assert 672 >> 4 == 42;
//@ assert (58 & 47) == 42;
//@ assert (34 | 8) == 42;
//@ assert (63 ^ 21) == 42;
//@ assert 168 / 4 == 42;
}
open Cil_types
let fold t =
match t.term_node with
| TSizeOf _ | TSizeOfStr _ | TSizeOfE _ | TAlignOf _ | TAlignOfE _
| TUnOp _ | TBinOp _ ->
let t' = Cil.constFoldTerm t in
Format.printf " %a folds to %a@." Cil_printer.pp_term t Cil_printer.pp_term t'
| _ -> ()
class visitTerm prj = object(_)
inherit Visitor.frama_c_copy prj
method! vterm t =
fold t;
Cil.DoChildren
end
let test_terms () =
let open Cil_builder.Exp in
let loc = Cil_datatype.Location.unknown in
let e1 = lognot ((of_int 21) + (of_int 21)) in
let e2 = lognot ((of_int 21) - (of_int 21)) in
let t1 = cil_term ~loc e1 in
let t2 = cil_term ~loc e2 in
Format.printf "Custom terms : @.";
fold t1;
fold t2
let startup () =
test_terms ();
Format.printf "File terms : @.";
let prj = File.create_project_from_visitor "test_const_fold"
(fun prj -> new visitTerm prj)
in
Project.set_current prj
let () = Boot.Main.extend startup
[kernel] Parsing const_fold_term.i (no preprocessing)
Custom terms :
!(21 + 21) folds to 1
!(21 - 21) folds to 0
File terms :
-(21 + 21) folds to -42
21 + 21 folds to 42
~21 folds to -22
-a folds to -a
(21 + 21) + a folds to (21 + 21) + a
21 + 21 folds to 42
84 - 42 folds to 42
6 * 7 folds to 42
21 << 1 folds to 42
672 >> 4 folds to 42
58 & 47 folds to 42
34 | 8 folds to 42
63 ^ 21 folds to 42
168 / 4 folds to 168 / 4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment