• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GCC with patches for OS216


Commit MetaInfo

Revision9d50112acfc01f85fe0fb6d88b329e6122e817b3 (tree)
Time2020-07-02 18:03:33
AuthorJakub Jelinek <jakub@redh...>
CommiterJakub Jelinek

Log Message

openmp: Diagnose non-rectangular loops with invalid steps

THe OpenMP 5 standard requires that if some loop in OpenMP loop nest refers
to some outer loop's iterator variable, then the subtraction of the multiplication
factors for the outer iterator multiplied by the outer increment modulo the
inner increment is 0. For loops with non-constants in any of these we can't
diagnose it, it would be a task for something like -fsanitize=openmp,
but if all these are constant, we can diagnose it.

2020-07-02 Jakub Jelinek <jakub@redhat.com>

* omp-expand.c (expand_omp_for): Diagnose non-rectangular loops with
invalid steps - ((m2 - m1) * incr_outer) % incr must be 0 in valid
OpenMP non-rectangular loops. Use XALLOCAVEC.

* c-c++-common/gomp/loop-7.c: New test.

Change Summary

Incremental Difference

--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -7122,15 +7122,55 @@ expand_omp_for (struct omp_region *region, gimple *inner_stmt)
71227122 struct omp_for_data fd;
71237123 struct omp_for_data_loop *loops;
71247124
7125- loops
7126- = (struct omp_for_data_loop *)
7127- alloca (gimple_omp_for_collapse (last_stmt (region->entry))
7128- * sizeof (struct omp_for_data_loop));
7125+ loops = XALLOCAVEC (struct omp_for_data_loop,
7126+ gimple_omp_for_collapse (last_stmt (region->entry)));
71297127 omp_extract_for_data (as_a <gomp_for *> (last_stmt (region->entry)),
71307128 &fd, loops);
71317129 region->sched_kind = fd.sched_kind;
71327130 region->sched_modifiers = fd.sched_modifiers;
71337131 region->has_lastprivate_conditional = fd.lastprivate_conditional != 0;
7132+ if (fd.non_rect && !gimple_omp_for_combined_into_p (fd.for_stmt))
7133+ {
7134+ for (int i = fd.first_nonrect; i <= fd.last_nonrect; i++)
7135+ if ((loops[i].m1 || loops[i].m2)
7136+ && (loops[i].m1 == NULL_TREE
7137+ || TREE_CODE (loops[i].m1) == INTEGER_CST)
7138+ && (loops[i].m2 == NULL_TREE
7139+ || TREE_CODE (loops[i].m2) == INTEGER_CST)
7140+ && TREE_CODE (loops[i].step) == INTEGER_CST
7141+ && TREE_CODE (loops[i - loops[i].outer].step) == INTEGER_CST)
7142+ {
7143+ tree t;
7144+ tree itype = TREE_TYPE (loops[i].v);
7145+ if (loops[i].m1 && loops[i].m2)
7146+ t = fold_build2 (MINUS_EXPR, itype, loops[i].m2, loops[i].m1);
7147+ else if (loops[i].m1)
7148+ t = fold_build1 (NEGATE_EXPR, itype, loops[i].m1);
7149+ else
7150+ t = loops[i].m2;
7151+ t = fold_build2 (MULT_EXPR, itype, t,
7152+ fold_convert (itype,
7153+ loops[i - loops[i].outer].step));
7154+ if (TYPE_UNSIGNED (itype) && loops[i].cond_code == GT_EXPR)
7155+ t = fold_build2 (TRUNC_MOD_EXPR, itype,
7156+ fold_build1 (NEGATE_EXPR, itype, t),
7157+ fold_build1 (NEGATE_EXPR, itype,
7158+ fold_convert (itype,
7159+ loops[i].step)));
7160+ else
7161+ t = fold_build2 (TRUNC_MOD_EXPR, itype, t,
7162+ fold_convert (itype, loops[i].step));
7163+ if (integer_nonzerop (t))
7164+ error_at (gimple_location (fd.for_stmt),
7165+ "invalid OpenMP non-rectangular loop step; "
7166+ "%<(%E - %E) * %E%> is not a multiple of loop %d "
7167+ "step %qE",
7168+ loops[i].m2 ? loops[i].m2 : integer_zero_node,
7169+ loops[i].m1 ? loops[i].m1 : integer_zero_node,
7170+ loops[i - loops[i].outer].step, i + 1,
7171+ loops[i].step);
7172+ }
7173+ }
71347174
71357175 gcc_assert (EDGE_COUNT (region->entry->succs) == 2);
71367176 BRANCH_EDGE (region->entry)->flags &= ~EDGE_ABNORMAL;
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/loop-7.c
@@ -0,0 +1,24 @@
1+void
2+foo (void)
3+{
4+ #pragma omp for collapse(2) /* { dg-error "invalid OpenMP non-rectangular loop step" } */
5+ for (int i = 0; i < 6; i++)
6+ for (int j = 4 * i; j < 7 * i; j += 2)
7+ ;
8+ #pragma omp for collapse(2) /* { dg-error "invalid OpenMP non-rectangular loop step" } */
9+ for (int i = 0; i < 32; i += 7)
10+ for (int j = 3 * i; j < 7 * i; j += 30)
11+ ;
12+ #pragma omp for collapse(2)
13+ for (int i = 0; i < 6; i++)
14+ for (int j = 4 * i; j < 6 * i; j += 2)
15+ ;
16+ #pragma omp for collapse(2)
17+ for (int i = 0; i < 6; i += 2)
18+ for (int j = 4 * i; j < 7 * i; j += 2)
19+ ;
20+ #pragma omp for collapse(2)
21+ for (int i = 0; i < 6; i += 5)
22+ for (int j = 4 * i; j < 7 * i; j += 15)
23+ ;
24+}