This is the mail archive of the gcc-patches@gcc.gnu.org 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]

[tree-ssa] PATCH to gimplify_cond_expr


In C++, for an expression like

  (foo() && bar () == 5) ? 1 : (abort(), 0);

if bar() returns a temporary class object, it is destroyed after the whole
COND_EXPR is evaluated.  After expanding the shortcut semantics, we were
generating code that looked something like

  T.1 = foo ();
  if (T.1)
    ;
  else
    goto no;
  try {
    T.2 = bar ();
    T.3 = operator == (&T.2, 5);
    if (T.3)
      goto yes;
    else
      goto no;
    yes:
      iftmp.4 = 1;
      goto done;
    no:
      abort ();
    done:;
  } finally {
    destroy T.2;
  }

Note the first "goto no;" which jumps into a try block.  This is bad and
wrong.

This is fixed by pushing into a conditional context before gimplifying the
expanded form.

Fixes 27_io/basic_ostream/inserters_arithmetic/*/1.cc.

Tested athlon-pc-linux-gnu, applied to tree-ssa branch.

2003-08-05  Jason Merrill  <jason@redhat.com>

	* gimplify.c (gimplify_cond_expr): Gimplify shortcut expansion in
	a conditional context.

Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.66
diff -c -p -r1.1.2.66 gimplify.c
*** gimplify.c	30 Jul 2003 19:24:10 -0000	1.1.2.66
--- gimplify.c	5 Aug 2003 20:16:38 -0000
*************** gimplify_cond_expr (tree *expr_p, tree *
*** 1871,1879 ****
  
        if (expr != *expr_p)
  	{
- 	  /* Don't gimplify our children now; gimplify_expr will re-gimplify
- 	     us, since we've changed *expr_p.  */
  	  *expr_p = expr;
  	  return;
  	}
      }
--- 1871,1885 ----
  
        if (expr != *expr_p)
  	{
  	  *expr_p = expr;
+ 
+ 	  /* We can't rely on gimplify_expr to re-gimplify the expanded
+ 	     form properly, as cleanups might cause the target labels to be
+ 	     wrapped in a TRY_FINALLY_EXPR.  To prevent that, we need to
+ 	     set up a conditional context.  */
+ 	  gimple_push_condition ();
+ 	  gimplify_stmt (expr_p);
+ 	  gimple_pop_condition (pre_p);
  	  return;
  	}
      }

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