This patch fixes two ICEs on valid testcases and one ICE on an invalid
testcase.  In the former, we should check for EXPR_P (as in the fix for
PR58516) before using SET_EXPR_LOCATION; in the latter we should bail
out early if the return-expression is the error_mark_node, otherwise
subsequent call of fold_build_cleanup_point_expr will want to access
TREE_OPERANDs of that return-expression.

Regtested/bootstrapped on x86_64-linux, ok for trunk?  (I don't think
it merits backporting to 4.7/4.8, but let me know if you think
otherwise.)

2013-10-07  Marek Polacek  <pola...@redhat.com>

        PR c++/58635
cp/
        * semantics.c (finish_return_stmt): Return error_mark_node
        when error_operand_p of the expr is true.
        (build_transaction_expr): Check for EXPR_P before setting the
        expr location.
testsuite/
        * g++.dg/tm/pr58635-1.C: New test.
        * g++.dg/tm/pr58635-2.C: New test.

--- gcc/cp/semantics.c.mp       2013-10-07 15:49:10.801602065 +0200
+++ gcc/cp/semantics.c  2013-10-07 15:49:20.430638270 +0200
@@ -787,7 +787,8 @@ finish_return_stmt (tree expr)
 
   expr = check_return_expr (expr, &no_warning);
 
-  if (flag_openmp && !check_omp_return ())
+  if (error_operand_p (expr)
+      || (flag_openmp && !check_omp_return ()))
     return error_mark_node;
   if (!processing_template_decl)
     {
@@ -5221,7 +5222,8 @@ build_transaction_expr (location_t loc,
   if (noex)
     {
       expr = build_must_not_throw_expr (expr, noex);
-      SET_EXPR_LOCATION (expr, loc);
+      if (EXPR_P (expr))
+       SET_EXPR_LOCATION (expr, loc);
       TREE_SIDE_EFFECTS (expr) = 1;
     }
   ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
--- gcc/testsuite/g++.dg/tm/pr58635-1.C.mp      2013-10-07 16:01:54.230240270 
+0200
+++ gcc/testsuite/g++.dg/tm/pr58635-1.C 2013-10-07 15:58:15.431447142 +0200
@@ -0,0 +1,14 @@
+// { dg-do compile }
+// { dg-options "-std=c++11 -fgnu-tm" }
+
+int
+foo (void)
+{
+  return __transaction_atomic noexcept(false) (false);
+}
+
+int
+bar (int i)
+{
+  return __transaction_atomic noexcept(false) (i);
+}
--- gcc/testsuite/g++.dg/tm/pr58635-2.C.mp      2013-10-07 16:02:00.398262163 
+0200
+++ gcc/testsuite/g++.dg/tm/pr58635-2.C 2013-10-07 16:01:44.874206993 +0200
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-options "-std=c++11 -fgnu-tm" }
+
+int
+foo (void)
+{
+  return __transaction_atomic noexcept(false) (x); // { dg-error "was not 
declared in this scope" }
+}

        Marek

Reply via email to