aboutsummaryrefslogtreecommitdiff
path: root/gcc/omp-low.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-05-11 09:07:47 +0200
committerJakub Jelinek <jakub@redhat.com>2021-05-11 09:07:47 +0200
commit98acbb3111fcb5e57d5e63d46c0d92f4e53e3c2a (patch)
treed1203880287bb5726e87729b40c09fe2946a4967 /gcc/omp-low.c
parent1866182f6cf338880c68225d9de571b787b6abcd (diff)
downloadgcc-98acbb3111fcb5e57d5e63d46c0d92f4e53e3c2a.zip
gcc-98acbb3111fcb5e57d5e63d46c0d92f4e53e3c2a.tar.gz
gcc-98acbb3111fcb5e57d5e63d46c0d92f4e53e3c2a.tar.bz2
openmp: Fix up taskloop reduction ICE if taskloop has no iterations [PR100471]
When a taskloop doesn't have any iterations, GOMP_taskloop* takes an early return, doesn't create any tasks and more importantly, doesn't create a taskgroup and doesn't register task reductions. But, the code emitted in the callers assumes task reductions have been registered and performs the reduction handling and task reduction unregistration. The pointer to the task reduction private variables is reused, on input it is the alignment and only on output it is the pointer, so in the case taskloop with no iterations the caller attempts to dereference the alignment value as if it was a pointer and crashes. We could in the early returns register the task reductions only to have them looped over and unregistered in the caller, but I think it is better to tell the caller there is nothing to task reduce and bypass all that. 2021-05-11 Jakub Jelinek <jakub@redhat.com> PR middle-end/100471 * omp-low.c (lower_omp_task_reductions): For OMP_TASKLOOP, if data is 0, bypass the reduction loop including GOMP_taskgroup_reduction_unregister call. * taskloop.c (GOMP_taskloop): If GOMP_TASK_FLAG_REDUCTION and not GOMP_TASK_FLAG_NOGROUP, when doing early return clear the task reduction pointer. * testsuite/libgomp.c/task-reduction-4.c: New test.
Diffstat (limited to 'gcc/omp-low.c')
-rw-r--r--gcc/omp-low.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 8b31362..c0ce1a4 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -8781,7 +8781,7 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
tree num_thr_sz = create_tmp_var (size_type_node);
tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
tree lab2 = create_artificial_label (UNKNOWN_LOCATION);
- tree lab3 = NULL_TREE;
+ tree lab3 = NULL_TREE, lab7 = NULL_TREE;
gimple *g;
if (code == OMP_FOR || code == OMP_SECTIONS)
{
@@ -8846,6 +8846,14 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
NULL_TREE, NULL_TREE);
tree data = create_tmp_var (pointer_sized_int_node);
gimple_seq_add_stmt (end, gimple_build_assign (data, t));
+ if (code == OMP_TASKLOOP)
+ {
+ lab7 = create_artificial_label (UNKNOWN_LOCATION);
+ g = gimple_build_cond (NE_EXPR, data,
+ build_zero_cst (pointer_sized_int_node),
+ lab1, lab7);
+ gimple_seq_add_stmt (end, g);
+ }
gimple_seq_add_stmt (end, gimple_build_label (lab1));
tree ptr;
if (TREE_CODE (TYPE_SIZE_UNIT (record_type)) == INTEGER_CST)
@@ -9209,6 +9217,8 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
g = gimple_build_call (t, 1, build_fold_addr_expr (avar));
}
gimple_seq_add_stmt (end, g);
+ if (lab7)
+ gimple_seq_add_stmt (end, gimple_build_label (lab7));
t = build_constructor (atype, NULL);
TREE_THIS_VOLATILE (t) = 1;
gimple_seq_add_stmt (end, gimple_build_assign (avar, t));