Skip to content
Snippets Groups Projects
Commit 6c233a74 authored by Andre Maroneze's avatar Andre Maroneze
Browse files

Merge branch 'fix/virgile/821-typing-error' into 'master'

[typing] only scalar types can be casted to _Bool

Closes #821

See merge request frama-c/frama-c!2573
parents 4eab981c 011c1626
No related merge requests found
...@@ -1349,15 +1349,19 @@ let makeCastT ~(e: exp) ~(oldt: typ) ~(newt: typ) = ...@@ -1349,15 +1349,19 @@ let makeCastT ~(e: exp) ~(oldt: typ) ~(newt: typ) =
let makeCast ~(e: exp) ~(newt: typ) = let makeCast ~(e: exp) ~(newt: typ) =
makeCastT e (typeOf e) newt makeCastT e (typeOf e) newt
(* A cast that is used for conditional expressions. Pointers are Ok. let is_scalar_type t =
Abort if invalid *) match unrollType t with
let checkBool (ot : typ) (_ : exp) =
match unrollType ot with
| TInt _ | TInt _
| TPtr _ | TPtr _
| TEnum _ | TEnum _
| TFloat _ -> () | TFloat _ -> true
| _ -> Kernel.fatal ~current:true "castToBool %a" Cil_printer.pp_typ ot | _ -> false
(* A cast that is used for conditional expressions. Pointers are Ok.
Abort if invalid *)
let checkBool (ot : typ) (_ : exp) =
if not (is_scalar_type ot) then
Kernel.fatal ~current:true "castToBool %a" Cil_printer.pp_typ ot
(* Evaluate constants to CTrue (non-zero) or CFalse (zero) *) (* Evaluate constants to CTrue (non-zero) or CFalse (zero) *)
let rec isConstTrueFalse c: [ `CTrue | `CFalse ] = let rec isConstTrueFalse c: [ `CTrue | `CFalse ] =
...@@ -2838,7 +2842,7 @@ let rec castTo ?context ?(fromsource=false) ...@@ -2838,7 +2842,7 @@ let rec castTo ?context ?(fromsource=false)
match ot', nt' with match ot', nt' with
| TNamed _, _ | TNamed _, _
| _, TNamed _ -> Kernel.fatal ~current:true "unrollType failed in castTo" | _, TNamed _ -> Kernel.fatal ~current:true "unrollType failed in castTo"
| _, TInt(IBool,_) -> | t, TInt(IBool,_) when is_scalar_type t ->
if is_boolean_result e then result if is_boolean_result e then result
else else
nt, nt,
......
[kernel] Parsing tests/syntax/wrong-assignment.i (no preprocessing)
[kernel] tests/syntax/wrong-assignment.i:7: Failure: castTo ebool -> _Bool
[kernel] User Error: stopping on file "tests/syntax/wrong-assignment.i" that has errors.
[kernel] Frama-C aborted: invalid user input.
typedef struct { _Bool a; } ebool;
ebool b, c;
void d() {
// this assignment should be rejected
c.a = b;
}
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