diff mbox

Fix up omp sections expansion

Message ID 20130919120232.GU1817@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Sept. 19, 2013, 12:02 p.m. UTC
Hi!

If sections construct has all section directives non-fallthru, as in
the attached testcase, including the case where they can be all or some of
them cancelled, we generate too large argument for GOMP_sections_start,
so if there are more threads than section directives (including the implicit
first) in the sections construct, we can __builtin_trap ().

Fixed thusly, tested on x86_64-linux and i686-linux, committed to trunk/4.8.

2013-09-19  Jakub Jelinek  <jakub@redhat.com>

	* omp-low.c (expand_omp_sections): Always pass len - 1 to
	GOMP_sections_start, even if !exit_reachable.
libgomp/
	* testsuite/libgomp.c/sections-2.c: New test.


	Jakub
diff mbox

Patch

--- gcc/omp-low.c.jj	2013-09-19 09:15:08.000000000 +0200
+++ gcc/omp-low.c	2013-09-19 12:59:49.325031241 +0200
@@ -6862,8 +6862,7 @@  expand_omp_sections (struct omp_region *
     {
       /* If we are not inside a combined parallel+sections region,
 	 call GOMP_sections_start.  */
-      t = build_int_cst (unsigned_type_node,
-			 exit_reachable ? len - 1 : len);
+      t = build_int_cst (unsigned_type_node, len - 1);
       u = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS_START);
       stmt = gimple_build_call (u, 1, t);
     }
--- libgomp/testsuite/libgomp.c/sections-2.c.jj	2013-09-19 13:06:46.138913032 +0200
+++ libgomp/testsuite/libgomp.c/sections-2.c	2013-09-19 13:07:00.250841349 +0200
@@ -0,0 +1,29 @@ 
+/* { dg-do run } */
+
+#include <stdlib.h>
+#include <unistd.h>
+
+__attribute__((noinline, noclone, noreturn))
+void
+foo ()
+{
+  sleep (4);
+  exit (0);
+}
+
+int
+main ()
+{
+  #pragma omp parallel
+  {
+    #pragma omp sections
+      {
+        foo ();
+      #pragma omp section
+        foo ();
+      #pragma omp section
+        foo ();
+      }
+  }
+  return 0;
+}