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]

[C++ PATCH] Fix ICE due to Cilk+ related cp_gimplify_expr bug (PR objc++/68511, PR c++/69213)


Hi!

If errors are reported in unrelated functions, then due to recent
Cilk+ related change in cp_gimplify_expr basically all gimplification
results in almost no statements to be added to the IL, while returning
SSA_NAMEs set by the missing code, because for INIT_EXPRs cp_gimplify_expr
would just return GS_ERROR if seen_error () instead of actually doing
anything.

Igor has posted a fix for this a month ago:
https://gcc.gnu.org/ml/gcc-patches/2015-12/msg00651.html
but that fix still looks wrong to me, it seems it will just limit
the problems to functions that originally contained at least one
_Cilk_spawn.

The fix limits the GS_ERROR to a) functions that contain _Cilk_spawn
b) if cilk_detect_spawn_and_unwrap fails (that can be for two reasons,
that _Cilk_spawn is not present at all, or if it is present, but used
in incorrect place) c) if _Cilk_spawn is present in the expression.
As cilk_detect_spawn_and_unwrap will already report error if it is present,
but in incorrect place, the c) test is guarded with seen_error (), so there
is no additional compile time cost in correct programs (or functions not
containing _Cilk_spawn at all).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-01-11  Jakub Jelinek  <jakub@redhat.com>

	PR objc++/68511
	PR c++/69213
	* cp-gimplify.c (cp_gimplify_expr) <case INIT_EXPR>: Don't return
	GS_ERROR whenever seen_error (), only if *expr_p contains
	cilk spawn stmt, but cilk_detect_spawn_and_unwrap failed.

	* g++.dg/opt/pr69213.C: New test.

--- gcc/cp/cp-gimplify.c.jj	2016-01-04 14:55:57.000000000 +0100
+++ gcc/cp/cp-gimplify.c	2016-01-11 13:22:36.475552358 +0100
@@ -617,14 +617,17 @@ cp_gimplify_expr (tree *expr_p, gimple_s
 	 LHS of an assignment might also be involved in the RHS, as in bug
 	 25979.  */
     case INIT_EXPR:
-      if (fn_contains_cilk_spawn_p (cfun)
-	  && cilk_detect_spawn_and_unwrap (expr_p))
+      if (fn_contains_cilk_spawn_p (cfun))
 	{
-	  cilk_cp_gimplify_call_params_in_spawned_fn (expr_p, pre_p, post_p);
-	  return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
+	  if (cilk_detect_spawn_and_unwrap (expr_p))
+	    {
+	      cilk_cp_gimplify_call_params_in_spawned_fn (expr_p,
+							  pre_p, post_p);
+	      return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
+	    }
+	  if (seen_error () && contains_cilk_spawn_stmt (*expr_p))
+	    return GS_ERROR;
 	}
-      if (seen_error ())
-	return GS_ERROR;
 
       cp_gimplify_init_expr (expr_p);
       if (TREE_CODE (*expr_p) != INIT_EXPR)
--- gcc/testsuite/g++.dg/opt/pr69213.C.jj	2016-01-11 13:18:05.949292994 +0100
+++ gcc/testsuite/g++.dg/opt/pr69213.C	2016-01-11 13:18:53.276638586 +0100
@@ -0,0 +1,18 @@
+// PR c++/69213
+// { dg-do compile }
+// { dg-options "-O3" }
+
+int a, b;
+
+void
+foo (void)
+{
+  __asm__ ("# %0" : : : "memory");	// { dg-error "operand number out of range" }
+}
+
+int
+main ()
+{
+  for (; a < 0; b++)
+    a = b;
+}


	Jakub


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