On Fri, Mar 29, 2013 at 11:01:30AM -0500, dagr...@rockwellcollins.com wrote:
> I suspect that CIL is not evaluating builtin_types_compatible_p
> correctly/at all.
It is evaluating it, but not correctly: it tests for type equality,
not compatibility. The gcc doc explains roughly the difference, but
does not give a very precise semantics:
http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
Attached is a quick and dirty patch to fix the case of arrays, making your
example compile, but I'm afraid something more complete about type
compatibility would need to be written.
An alternative would be to preserve the __builtin and let gcc evaluate it. It
would be the safest solution and only a minor change in CIL, but some
existing programs might rely on the fact that CIL performs the exanpansion.
Best,
--
Gabriel
diff --git a/src/cil.ml b/src/cil.ml
index 0f5035f..9da6402 100755
--- a/src/cil.ml
+++ b/src/cil.ml
@@ -5908,8 +5908,8 @@ let typeSigAddAttrs a0 t =
(* Compute a type signature.
Use ~ignoreSign:true to convert all signed integer types to unsigned,
so that signed and unsigned will compare the same. *)
-let rec typeSigWithAttrs ?(ignoreSign=false) doattr t =
- let typeSig = typeSigWithAttrs ~ignoreSign doattr in
+let rec typeSigWithAttrs ?(ignoreSign=false) ?(ignoreArraySize=false) doattr t =
+ let typeSig = typeSigWithAttrs ~ignoreSign ~ignoreArraySize doattr in
let attrVisitor = new typeSigVisitor typeSig in
let doattr al = visitCilAttributes attrVisitor (doattr al) in
match t with
@@ -5922,6 +5922,8 @@ let rec typeSigWithAttrs ?(ignoreSign=false) doattr t =
| TVoid al -> TSBase (TVoid (doattr al))
| TEnum (enum, a) -> TSEnum (enum.ename, doattr a)
| TPtr (t, a) -> TSPtr (typeSig t, doattr a)
+ | TArray (t,l,a) when ignoreArraySize ->
+ TSArray(typeSig t, None, doattr a)
| TArray (t,l,a) -> (* We do not want fancy expressions in array lengths.
* So constant fold the lengths *)
let l' =
diff --git a/src/cil.mli b/src/cil.mli
index c48124d..0466ea3 100644
--- a/src/cil.mli
+++ b/src/cil.mli
@@ -1512,7 +1512,7 @@ val typeSig: typ -> typsig
(** Like {!Cil.typeSig} but customize the incorporation of attributes.
Use ~ignoreSign:true to convert all signed integer types to unsigned,
so that signed and unsigned will compare the same. *)
-val typeSigWithAttrs: ?ignoreSign:bool -> (attributes -> attributes) -> typ -> typsig
+val typeSigWithAttrs: ?ignoreSign:bool -> ?ignoreArraySize:bool -> (attributes -> attributes) -> typ -> typsig
(** Replace the attributes of a signature (only at top level) *)
val setTypeSigAttrs: attributes -> typsig -> typsig
diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml
index 2d35a8a..e9f44b3 100644
--- a/src/frontc/cabs2cil.ml
+++ b/src/frontc/cabs2cil.ml
@@ -4326,7 +4326,8 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
(* Drop the side-effects *)
prechunk := (fun _ -> empty);
piscall := false;
- if Util.equals (typeSig t1) (typeSig t2) then
+ let tSig = typeSigWithAttrs ~ignoreArraySize:true (fun a -> a) in
+ if Util.equals (tSig t1) (tSig t2) then
pres := integer 1
else
pres := integer 0;
------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete
for recognition, cash, and the chance to get your game on Steam.
$5K grand prize plus 10 genre and skill prizes. Submit your demo
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users