Skip to content

Commit

Permalink
Ensure complex have the correct fkind rather than having the "complex…
Browse files Browse the repository at this point in the history
…" attribute

And also check this in check.ml
  • Loading branch information
michael-schwarz committed Jan 16, 2020
1 parent 1d71297 commit 7e85e55
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ let rec checkType (t: typ) (ctx: ctxType) =
match t with
(TVoid a | TBuiltin_va_list a) -> checkAttributes a
| TInt (ik, a) -> checkAttributes a
| TFloat (_, a) -> checkAttributes a
| TFloat (_, a) ->
checkAttributes a;
if hasAttribute "complex" a then
E.s (E.bug "float type has attribute complex, this should never be the case as there are fkinds for this");
| TPtr (t, a) -> checkAttributes a; checkType t CTPtr

| TNamed (ti, a) ->
Expand Down
9 changes: 9 additions & 0 deletions src/cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,15 @@ let typeOfReal t =
TFloat (newfkind fkind, newattrs)
| _ -> E.s (E.bug "unexpected non-numerical type for argument to __real__")

(** for an fkind, return the corresponding complex fkind *)
let getComplexFkind = function
| FFloat -> FComplexFloat
| FDouble -> FComplexDouble
| FLongDouble -> FComplexLongDouble
| FComplexFloat -> FComplexFloat
| FComplexDouble -> FComplexDouble
| FComplexLongDouble -> FComplexLongDouble

let var vi : lval = (Var vi, NoOffset)
(* let assign vi e = Instrs(Set (var vi, e), lu) *)

Expand Down
3 changes: 3 additions & 0 deletions src/cil.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,9 @@ val isVoidPtrType: typ -> bool
(** for numerical __complex types return type of corresponding real part *)
val typeOfReal: typ -> typ

(** for an fkind, return the corresponding complex fkind *)
val getComplexFkind: fkind -> fkind

(** int *)
val intType: typ

Expand Down
27 changes: 16 additions & 11 deletions src/frontc/cabs2cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1496,9 +1496,9 @@ let cabsTypeAddAttributes a0 t =
t
| _ ->
(* anything else: add a0 to existing attributes *)
let add (a: attributes) = cabsAddAttributes a0 a in
let addA0To (a: attributes) = cabsAddAttributes a0 a in
match t with
TVoid a -> TVoid (add a)
TVoid a -> TVoid (addA0To a)
| TInt (ik, a) ->
(* Here we have to watch for the mode attribute *)
(* sm: This stuff is to handle a GCC extension where you can request integers*)
Expand All @@ -1512,7 +1512,7 @@ let cabsTypeAddAttributes a0 t =
(* A consequence of this handling is that we throw away the mode *)
(* attribute, which we used to go out of our way to avoid printing anyway.*)
(* DG: Use machine model to pick correct type *)
let ik', a0' =
let ik', a0' = begin
(* Go over the list of new attributes and come back with a
* filtered list and a new integer kind *)
List.fold_left
Expand Down Expand Up @@ -1544,17 +1544,22 @@ let cabsTypeAddAttributes a0 t =
| _ -> (ik', a0one :: a0'))
(ik, [])
a0
end
in
TInt (ik', cabsAddAttributes a0' a)

| TFloat (fk, a) -> TFloat (fk, add a)
| TEnum (enum, a) -> TEnum (enum, add a)
| TPtr (t, a) -> TPtr (t, add a)
| TArray (t, l, a) -> TArray (t, l, add a)
| TFun (t, args, isva, a) -> TFun(t, args, isva, add a)
| TComp (comp, a) -> TComp (comp, add a)
| TNamed (t, a) -> TNamed (t, add a)
| TBuiltin_va_list a -> TBuiltin_va_list (add a)
| TFloat (fk, a) ->
if Cil.hasAttribute "complex" a0 then
TFloat (Cil.getComplexFkind fk, cabsAddAttributes (Cil.dropAttribute "complex" a0) a)
else
TFloat (fk, addA0To a)
| TEnum (enum, a) -> TEnum (enum, addA0To a)
| TPtr (t, a) -> TPtr (t, addA0To a)
| TArray (t, l, a) -> TArray (t, l, addA0To a)
| TFun (t, args, isva, a) -> TFun(t, args, isva, addA0To a)
| TComp (comp, a) -> TComp (comp, addA0To a)
| TNamed (t, a) -> TNamed (t, addA0To a)
| TBuiltin_va_list a -> TBuiltin_va_list (addA0To a)
end


Expand Down

0 comments on commit 7e85e55

Please sign in to comment.