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
8162a768
Commit
8162a768
authored
5 years ago
by
Virgile Prevosto
Browse files
Options
Downloads
Patches
Plain Diff
[logic] better typed expr_to_term conversion
argument of ACSL `!` is supposed to be a boolean, not an int
parent
ddee95a4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/kernel_services/ast_queries/logic_utils.ml
+34
-16
34 additions, 16 deletions
src/kernel_services/ast_queries/logic_utils.ml
with
34 additions
and
16 deletions
src/kernel_services/ast_queries/logic_utils.ml
+
34
−
16
View file @
8162a768
...
...
@@ -334,39 +334,42 @@ let is_zero_comparable t =
|
Ltype
_
->
false
|
Lvar
_
|
Larrow
_
->
false
let
scalar_term_
to_predicate
t
=
let
scalar_term_
conversion
conversion
t
=
let
loc
=
t
.
term_loc
in
let
conversion
zero
=
prel
~
loc
(
Cil_types
.
Rneq
,
t
,
zero
)
in
let
arith
_conversion
()
=
conversion
(
Cil
.
lzero
~
loc
()
)
in
let
ptr_
conversion
()
=
conversion
(
Logic_const
.
term
~
loc
Tnull
t
.
term_type
)
let
arith_
conversion
()
=
conversion
~
loc
(
Cil
.
lzero
~
loc
()
)
t
in
let
ptr
_conversion
()
=
conversion
~
loc
(
Logic_const
.
term
~
loc
Tnull
t
.
term_type
)
t
in
match
unroll_type
t
.
term_type
with
|
Ctype
(
TInt
_
)
->
arith_conversion
()
|
Ctype
(
TFloat
_
)
->
conversion
(
Logic_const
.
treal_zero
~
loc
~
ltyp
:
t
.
term_type
()
)
conversion
~
loc
(
Logic_const
.
treal_zero
~
loc
~
ltyp
:
t
.
term_type
()
)
t
|
Ctype
(
TPtr
_
)
->
ptr_conversion
()
|
Ctype
(
TArray
_
)
->
ptr_conversion
()
(* Could be transformed to \true: an array is never \null *)
|
Ctype
(
TFun
_
)
->
ptr_conversion
()
(* decay as pointer *)
|
Linteger
->
arith_conversion
()
|
Lreal
->
conversion
(
Logic_const
.
treal_zero
~
loc
()
)
|
Lreal
->
conversion
~
loc
(
Logic_const
.
treal_zero
~
loc
()
)
t
|
Ltype
({
lt_name
=
name
}
,
[]
)
when
name
=
Utf8_logic
.
boolean
->
let
ctrue
=
Logic_env
.
Logic_ctor_info
.
find
"
\\
true"
in
prel
~
loc
(
Cil_types
.
Req
,
t
,
{
term_node
=
TDataCons
(
ctrue
,
[]
);
term_loc
=
loc
;
term_type
=
Ltype
(
ctrue
.
ctor_type
,
[]
);
term_name
=
[]
;
})
let
ctrue
=
Logic_env
.
Logic_ctor_info
.
find
"
\\
false"
in
conversion
~
loc
(
term
~
loc
(
TDataCons
(
ctrue
,
[]
))
boolean_type
)
t
|
Ltype
_
|
Lvar
_
|
Larrow
_
|
Ctype
(
TVoid
_
|
TNamed
_
|
TComp
_
|
TEnum
_
|
TBuiltin_va_list
_
)
->
Kernel
.
fatal
"Cannot convert
to predicate
a term of type %a"
"Cannot convert a term of type %a"
Cil_printer
.
pp_logic_type
t
.
term_type
let
scalar_term_to_predicate
=
let
conversion
~
loc
zero
t
=
prel
~
loc
(
Cil_types
.
Rneq
,
t
,
zero
)
in
scalar_term_conversion
conversion
let
scalar_term_to_boolean
=
let
conversion
~
loc
zero
t
=
term
~
loc
(
TBinOp
(
Ne
,
t
,
zero
))
Logic_const
.
boolean_type
in
scalar_term_conversion
conversion
let
rec
expr_to_term
~
cast
e
=
let
e_typ
=
unrollType
(
Cil
.
typeOf
e
)
in
let
loc
=
e
.
eloc
in
...
...
@@ -403,6 +406,21 @@ let rec expr_to_term ~cast e =
end
|
UnOp
(
op
,
u
,
_
)
->
let
u'
=
expr_to_term_coerce
~
cast
u
in
let
u'
=
match
op
with
|
Cil_types
.
LNot
->
(
match
u'
.
term_node
with
|
TCastE
(
_
,
t
)
when
is_boolean_type
t
.
term_type
->
t
|
_
when
is_boolean_type
u'
.
term_type
->
u'
|
_
when
is_zero_comparable
u'
->
scalar_term_to_boolean
u'
|
_
->
Kernel
.
fatal
"expr_to_term: unexpected argument of ! operator %a, \
converted to %a"
Cil_printer
.
pp_exp
u
Cil_printer
.
pp_term
u'
)
|
_
->
u'
in
(* See comments for binop case above. *)
let
tcast
=
match
op
,
cast
with
|
Cil_types
.
LNot
,
_
->
Some
Logic_const
.
boolean_type
...
...
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