re PR middle-end/23155 (Gimplification failed for union cast)

2005-11-03  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/23155
        * g++.dg/ext/c99struct1.C: New test.
        * gcc.dg/union-cast-1.c: New test.
        * gcc.dg/union-cast-2.c: New test.
        * gcc.dg/union-cast-3.c: New test.

2005-11-03  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/23155
        * gimplifier.c (gimplify_expr): Create a temporary for lvalue
        CONSTRUCTOR.

From-SVN: r106438
This commit is contained in:
Andrew Pinski 2005-11-03 16:15:53 +00:00 committed by Andrew Pinski
parent 031905948a
commit ca0b7d18c1
7 changed files with 78 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/23155
* gimplifier.c (gimplify_expr): Create a temporary for lvalue
CONSTRUCTOR.
2005-11-03 Daniel Berlin <dberlin@dberlin.org>
Fix PR tree-optimization/24351

View File

@ -4323,6 +4323,15 @@ gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p,
*expr_p = temp;
ret = GS_OK;
}
/* C99 code may assign to an array in a constructed
structure or union, and this has undefined behavior only
on execution, so create a temporary if an lvalue is
required. */
else if (fallback == fb_lvalue)
{
*expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p);
lang_hooks.mark_addressable (*expr_p);
}
else
ret = GS_ALL_DONE;
break;

View File

@ -1,3 +1,11 @@
2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/23155
* g++.dg/ext/c99struct1.C: New test.
* gcc.dg/union-cast-1.c: New test.
* gcc.dg/union-cast-2.c: New test.
* gcc.dg/union-cast-3.c: New test.
2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/24589

View File

@ -0,0 +1,12 @@
// { dg-options "" }
// C99 anon struct variable with array accesses.
struct s { int a[1]; };
void
foo5 (void)
{
((struct s) { { 0 } }).a[0] = 1;
}

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu89" } */
/* A combine of two extensions to C89 are used here.
First casts to unions is used.
Second subscripting non lvalue arrays, this is in C99. */
union vx {short f[8]; int v;};
int vec;
void
foo5 (int vec)
{
((union vx) vec).f[5] = 1;
}

View File

@ -0,0 +1,15 @@
/* { dg-do compile } */
/* { dg-options "-std=c89 -pedantic-errors" } */
/* PR 23155
We should get two error messages, one about union cast
and the other about array access for non lvalues. */
union vx {short f[8]; int v;};
int vec;
void
foo5 (int vec)
{
((union vx) vec).f[5] = 1; /* { dg-error "(forbids subscripting)|(forbids casts to union type)" } */
}

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-std=c99 -pedantic-errors" } */
/* PR 23155
We should get one error messag, one about union cast. */
union vx {short f[8]; int v;};
int vec;
void
foo5 (int vec)
{
((union vx) vec).f[5] = 1; /* { dg-error "forbids casts to union type" } */
}