Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
846211fa
Commit
846211fa
authored
4 years ago
by
Virgile Prevosto
Browse files
Options
Downloads
Patches
Plain Diff
[logic] add a test for expr_to_predicate
parent
b05f192a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/spec/expr_to_term.i
+15
-1
15 additions, 1 deletion
tests/spec/expr_to_term.i
tests/spec/expr_to_term.ml
+30
-0
30 additions, 0 deletions
tests/spec/expr_to_term.ml
tests/spec/oracle/expr_to_term.res.oracle
+21
-0
21 additions, 0 deletions
tests/spec/oracle/expr_to_term.res.oracle
with
66 additions
and
1 deletion
tests/spec/expr_to_term.i
+
15
−
1
View file @
846211fa
/* run.config
/* run.config
MODULE: @PTEST_DIR@/@PTEST_NAME@.cmxs
MODULE: @PTEST_DIR@/@PTEST_NAME@.cmxs
OPT: -print
OPT:
-keep-logical-operators
-print
*/
*/
...
@@ -43,3 +43,17 @@ int g() {
...
@@ -43,3 +43,17 @@ int g() {
int
h
()
{
int
h
()
{
if (t<5) return 2; else return 3;
if (t<5) return 2; else return 3;
}
}
void
expr_to_predicate
(
int
x
)
{ }
int
z
,
t
;
/*@ ensures z!=0 && t!=0;
ensures !(z<5);
ensures (int)(t|5) != 0;
*/
void
i
()
{
expr_to_predicate(z&&t);
expr_to_predicate(!(z<5));
expr_to_predicate(t|5);
}
This diff is collapsed.
Click to expand it.
tests/spec/expr_to_term.ml
+
30
−
0
View file @
846211fa
...
@@ -24,6 +24,21 @@ let check_expr_term check fct s post =
...
@@ -24,6 +24,21 @@ let check_expr_term check fct s post =
let
post
=
Logic_const
.
new_predicate
app
in
let
post
=
Logic_const
.
new_predicate
app
in
Annotations
.
add_ensures
emitter
fct
[
Normal
,
post
]
Annotations
.
add_ensures
emitter
fct
[
Normal
,
post
]
let
check_expr_pred
fct
s
post
=
let
exp
=
match
s
.
skind
with
|
Instr
(
Call
(
_
,_,
[
x
]
,_
))
->
x
|
_
->
Kernel
.
fatal
"Unexpected statement %a"
Printer
.
pp_stmt
s
in
let
pred
=
(
snd
post
)
.
ip_content
.
tp_statement
in
let
pred'
=
Logic_utils
.
expr_to_predicate
exp
in
if
not
(
Logic_utils
.
is_same_predicate
pred
pred'
)
then
Kernel
.
fatal
"translation of C expression %a is %a, inconsistent with predicate %a"
Printer
.
pp_exp
exp
Printer
.
pp_predicate
pred'
Printer
.
pp_predicate
pred
;
let
post
=
Logic_const
.
new_predicate
pred'
in
Annotations
.
add_ensures
emitter
fct
[
Normal
,
post
]
let
treat_fct
check
fct
=
let
treat_fct
check
fct
=
let
stmts
=
(
Kernel_function
.
get_definition
fct
)
.
sbody
.
bstmts
in
let
stmts
=
(
Kernel_function
.
get_definition
fct
)
.
sbody
.
bstmts
in
let
stmts
=
let
stmts
=
...
@@ -47,16 +62,31 @@ let treat_fct check fct =
...
@@ -47,16 +62,31 @@ let treat_fct check fct =
List
.
iter2
(
check_expr_term
check
fct
)
stmts
ensures
;
List
.
iter2
(
check_expr_term
check
fct
)
stmts
ensures
;
Filecheck
.
check_ast
"check_expr_to_term"
Filecheck
.
check_ast
"check_expr_to_term"
let
treat_fct_pred
fct
=
let
stmts
=
(
Kernel_function
.
get_definition
fct
)
.
sbody
.
bstmts
in
let
stmts
=
List
.
filter
(
fun
x
->
match
x
.
skind
with
Instr
(
Call
_
)
->
true
|
_
->
false
)
stmts
in
let
ensures
=
(
List
.
hd
(
Annotations
.
funspec
fct
)
.
spec_behavior
)
.
b_post_cond
in
if
List
.
length
stmts
<>
List
.
length
ensures
then
Kernel
.
fatal
"ill-formed test in function %a"
Kernel_function
.
pretty
fct
;
List
.
iter2
(
check_expr_pred
fct
)
stmts
ensures
;
Filecheck
.
check_ast
"check_expr_to_predicate"
let
compute
()
=
let
compute
()
=
let
main
=
Globals
.
Functions
.
find_by_name
"main"
in
let
main
=
Globals
.
Functions
.
find_by_name
"main"
in
let
f
=
Globals
.
Functions
.
find_by_name
"f"
in
let
f
=
Globals
.
Functions
.
find_by_name
"f"
in
let
g
=
Globals
.
Functions
.
find_by_name
"g"
in
let
g
=
Globals
.
Functions
.
find_by_name
"g"
in
let
h
=
Globals
.
Functions
.
find_by_name
"h"
in
let
h
=
Globals
.
Functions
.
find_by_name
"h"
in
let
i
=
Globals
.
Functions
.
find_by_name
"i"
in
begin
begin
treat_fct
true
main
;
treat_fct
true
main
;
treat_fct
false
f
;
treat_fct
false
f
;
treat_fct
true
g
;
treat_fct
true
g
;
treat_fct
true
h
;
treat_fct
true
h
;
treat_fct_pred
i
;
end
end
let
()
=
Db
.
Main
.
extend
compute
let
()
=
Db
.
Main
.
extend
compute
This diff is collapsed.
Click to expand it.
tests/spec/oracle/expr_to_term.res.oracle
+
21
−
0
View file @
846211fa
...
@@ -76,4 +76,25 @@ int h(void)
...
@@ -76,4 +76,25 @@ int h(void)
return_label: return __retres;
return_label: return __retres;
}
}
void expr_to_predicate(int x_0)
{
return;
}
int z;
/*@ ensures (int)(t | 5) ≢ 0;
ensures ¬(z < 5);
ensures z ≢ 0 ∧ t ≢ 0;
ensures z ≢ 0 ∧ t ≢ 0;
ensures ¬(z < 5);
ensures (int)(t | 5) ≢ 0;
*/
void i(void)
{
expr_to_predicate((z && t) != 0);
expr_to_predicate(! (z < 5));
expr_to_predicate(t | 5);
return;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment