Commit 0257e383 by Richard Henderson Committed by Richard Henderson

re PR c/24255 (__transparent_union__ mishandled)

        PR c/24255
        * c-typeck.c (convert_for_assignment): Use build_constructor_single
        to initialize a transparent union instead of a nop_expr.

From-SVN: r105270
parent a4176272
2005-10-11 Richard Henderson <rth@redhat.com> 2005-10-11 Richard Henderson <rth@redhat.com>
PR c/24255
* c-typeck.c (convert_for_assignment): Use build_constructor_single
to initialize a transparent union instead of a nop_expr.
2005-10-11 Richard Henderson <rth@redhat.com>
* Makefile.in (tree-ssa-dce.o): Depend on SCEV_H. * Makefile.in (tree-ssa-dce.o): Depend on SCEV_H.
* tree-ssa-dce.c: Include tree-scalar-evolution.h. * tree-ssa-dce.c: Include tree-scalar-evolution.h.
(tree_ssa_dce_loop): Call scev_reset. (tree_ssa_dce_loop): Call scev_reset.
......
...@@ -3799,13 +3799,11 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3799,13 +3799,11 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type) else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type)
&& (errtype == ic_argpass || errtype == ic_argpass_nonproto)) && (errtype == ic_argpass || errtype == ic_argpass_nonproto))
{ {
tree memb_types; tree memb, marginal_memb = NULL_TREE;
tree marginal_memb_type = 0;
for (memb_types = TYPE_FIELDS (type); memb_types; for (memb = TYPE_FIELDS (type); memb ; memb = TREE_CHAIN (memb))
memb_types = TREE_CHAIN (memb_types))
{ {
tree memb_type = TREE_TYPE (memb_types); tree memb_type = TREE_TYPE (memb);
if (comptypes (TYPE_MAIN_VARIANT (memb_type), if (comptypes (TYPE_MAIN_VARIANT (memb_type),
TYPE_MAIN_VARIANT (rhstype))) TYPE_MAIN_VARIANT (rhstype)))
...@@ -3837,8 +3835,8 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3837,8 +3835,8 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
break; break;
/* Keep looking for a better type, but remember this one. */ /* Keep looking for a better type, but remember this one. */
if (!marginal_memb_type) if (!marginal_memb)
marginal_memb_type = memb_type; marginal_memb = memb;
} }
} }
...@@ -3852,13 +3850,13 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3852,13 +3850,13 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
} }
} }
if (memb_types || marginal_memb_type) if (memb || marginal_memb)
{ {
if (!memb_types) if (!memb)
{ {
/* We have only a marginally acceptable member type; /* We have only a marginally acceptable member type;
it needs a warning. */ it needs a warning. */
tree ttl = TREE_TYPE (marginal_memb_type); tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
tree ttr = TREE_TYPE (rhstype); tree ttr = TREE_TYPE (rhstype);
/* Const and volatile mean something different for function /* Const and volatile mean something different for function
...@@ -3893,12 +3891,14 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3893,12 +3891,14 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
"from pointer target type"), "from pointer target type"),
G_("return discards qualifiers from " G_("return discards qualifiers from "
"pointer target type")); "pointer target type"));
memb = marginal_memb;
} }
if (pedantic && (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))) if (pedantic && (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)))
pedwarn ("ISO C prohibits argument conversion to union type"); pedwarn ("ISO C prohibits argument conversion to union type");
return build1 (NOP_EXPR, type, rhs); return build_constructor_single (type, memb, rhs);
} }
} }
......
/* PR 24255 */
/* { dg-do run } */
/* { dg-options "-O" } */
extern void abort (void);
union wait { int w_status; };
typedef union
{
union wait *uptr;
int *iptr;
} WAIT_STATUS __attribute__ ((__transparent_union__));
int status;
union wait wstatus;
void __attribute__((noinline))
test1 (WAIT_STATUS s)
{
if (s.iptr != &status)
abort ();
}
void __attribute__((noinline))
test2 (WAIT_STATUS s)
{
if (s.uptr != &wstatus)
abort ();
}
int main()
{
test1 (&status);
test2 (&wstatus);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment