Do not try to approach them as "field-to-union" casts --- src/frontc/cabs2cil.ml | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml index 6c3d692..7833095 100644 --- a/src/frontc/cabs2cil.ml +++ b/src/frontc/cabs2cil.ml @@ -3099,6 +3099,8 @@ and preprocessCast (specs: A.specifier) (* If we are casting to a union type then we have to treat this as a * constructor expression. This is to handle the gcc extension that allows * cast from a type of a field to the type of the union *) + (* However, it may just be casting of a whole union to its own type. We + * will resolve this later, when we'll convert casts to unions. *) let ie' = match unrollType typ, ie with TComp (c, _), A.SINGLE_INIT _ when not c.cstruct -> @@ -5070,7 +5072,7 @@ and doInit (* We have a designator that tells us to select the matching union field. * This is to support a GCC extension *) - | TComp(ci, _), [(A.NEXT_INIT, + | TComp(ci, _) as targ, [(A.NEXT_INIT, A.COMPOUND_INIT [(A.INFIELD_INIT ("___matching_field", A.NEXT_INIT), A.SINGLE_INIT oneinit)])] @@ -5085,10 +5087,17 @@ and doInit -> fi | _ :: rest -> findField rest in - let fi = findField ci.cfields in - (* Change the designator and redo *) - doInit isconst setone so acc [(A.INFIELD_INIT (fi.fname, A.NEXT_INIT), - A.SINGLE_INIT oneinit)] + (* If this is a cast from union X to union X *) + if Util.equals tsig (typeSigNoAttrs targ) + then + doInit isconst setone so acc [(A.NEXT_INIT, A.SINGLE_INIT oneinit)] + else + (* If this is a GNU extension with field-to-union cast find the field *) + let fi = findField ci.cfields in + let _ = ignore (E.log "REDO" ) in + (* Change the designator and redo *) + doInit isconst setone so acc [(A.INFIELD_INIT (fi.fname, A.NEXT_INIT), + A.SINGLE_INIT oneinit)] (* A structure with a composite initializer. We initialize the fields*) -- 1.7.0.2 ------------------------------------------------------------------------------ Special Offer -- Download ArcSight Logger for FREE! Finally, a world-class log management solution at an even better price-free! And you'll get a free "Love Thy Logs" t-shirt when you download Logger. Secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsisghtdev2dev _______________________________________________ CIL-users mailing list CIL-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cil-users