This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fix PR40026, failure from COMPOUND_LITERAL_EXPR move to middle-end

This happened because optimize_compound_literals_in_ctor was previously
handled separately in the C front-end's gimplification hook, while now
it's part of the gimplifier proper.

What the C front-end was doing was to replace the CONSTRUCTOR in the
MODIFY_EXPR that was hosting it; I thought this was unnecessary when
doing it in gimplify_init_constructor, but I was wrong and the analysis
in the PR comments says why.

The old C front-end code was doing

-	  if (ctor != TREE_OPERAND (*expr_p, 1))
-	    {
-	      *expr_p = copy_node (*expr_p);
-	      TREE_OPERAND (*expr_p, 1) = ctor;
-	      return GS_OK;
-	    }

while I just patch TREE_OPERAND (*expr_p, 1).  I decided to do this
because gimplify.c never copies trees, it just patches in place all the

I took the opportunity to tighten an if into an assertion.  That it
holds should be obvious from inspection of the callers of

Bootstrapped/regtested i686-pc-linux-gnu, ok for trunk?

2009-05-11  Paolo Bonzini  <>

	PR tree-optimization/40026
	* gimplify.c (gimplify_init_constructor): Change initial conditional
	to assertion.  Rewrite TREE_OPERAND (*expr_p, 1) after

2009-05-11  Paolo Bonzini  <>

	PR tree-optimization/40026
	* gcc.c-torture/compile/pr40026.c: New testcase.

Index: gimplify.c
--- gimplify.c	(revision 147360)
+++ gimplify.c	(working copy)
@@ -3643,14 +3643,11 @@ static enum gimplify_status
 gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 			   bool want_value, bool notify_temp_creation)
-  tree object, new_ctor;
-  tree ctor = TREE_OPERAND (*expr_p, 1);
-  tree type = TREE_TYPE (ctor);
+  tree object, ctor, type;
   enum gimplify_status ret;
   VEC(constructor_elt,gc) *elts;
-  if (TREE_CODE (ctor) != CONSTRUCTOR)
-    return GS_UNHANDLED;
+  gcc_assert (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == CONSTRUCTOR);
   if (!notify_temp_creation)
@@ -3661,8 +3658,10 @@ gimplify_init_constructor (tree *expr_p,
   object = TREE_OPERAND (*expr_p, 0);
-  new_ctor = optimize_compound_literals_in_ctor (ctor);
-  elts = CONSTRUCTOR_ELTS (new_ctor);
+  ctor = TREE_OPERAND (*expr_p, 1) =
+    optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1));
+  type = TREE_TYPE (ctor);
+  elts = CONSTRUCTOR_ELTS (ctor);
   ret = GS_ALL_DONE;
   switch (TREE_CODE (type))

typedef struct {
    unsigned long bits;
} S;
struct T {
    S span;
    int flags;

struct T f(int x)
  return (struct T) {
      .span = (S) { 0UL },
      .flags = (x ? 256 : 0),

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]