Hi Jakub,
with the way that chunk_size < 1 is handled for gomp_iter_dynamic_next:
(1) chunk_size <= -1: wraps into large unsigned value, seems to work though.
(2) chunk_size == 0: infinite loop
The (2) behavior is obviously not desired. This patch fixes this by changing
the chunk_size initialization in gomp_loop_init to "max(1,chunk_size)"
The OMP_SCHEDULE parsing in libgomp/env.c has also been adjusted to reject
negative values.
Tested without regressions, and a new testcase for the infinite loop behavior
added.
Okay for trunk?
Thanks,
Chung-Lin
libgomp/ChangeLog:
* env.c (parse_schedule): Make negative values invalid for chunk_size.
* loop.c (gomp_loop_init): For non-STATIC schedule and chunk_size <= 0,
set initialized chunk_size to 1.
* testsuite/libgomp.c/loop-28.c: New test.
diff --git a/libgomp/env.c b/libgomp/env.c
index 1c4ee894515..dff07617e15 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -182,6 +182,8 @@ parse_schedule (void)
goto invalid;
errno = 0;
+ if (*env == '-')
+ goto invalid;
value = strtoul (env, &end, 10);
if (errno || end == env)
goto invalid;
diff --git a/libgomp/loop.c b/libgomp/loop.c
index be85162bb1e..018b4e9a8bd 100644
--- a/libgomp/loop.c
+++ b/libgomp/loop.c
@@ -41,7 +41,7 @@ gomp_loop_init (struct gomp_work_share *ws, long start, long
end, long incr,
enum gomp_schedule_type sched, long chunk_size)
{
ws->sched = sched;
- ws->chunk_size = chunk_size;
+ ws->chunk_size = (sched == GFS_STATIC || chunk_size > 1) ? chunk_size : 1;
/* Canonicalize loops that have zero iterations to ->next == ->end. */
ws->end = ((incr > 0 && start > end) || (incr < 0 && start < end))
? start : end;
diff --git a/libgomp/testsuite/libgomp.c/loop-28.c
b/libgomp/testsuite/libgomp.c/loop-28.c
new file mode 100644
index 00000000000..e3f852046f4
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/loop-28.c
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-timeout 10 } */
+
+void __attribute__((noinline))
+foo (int a[], int n, int chunk_size)
+{
+ #pragma omp parallel for schedule (dynamic,chunk_size)
+ for (int i = 0; i < n; i++)
+ a[i] = i;
+}
+
+int main (void)
+{
+ int a[100];
+ foo (a, 100, 0);
+ return 0;
+}