}
}
bool rect_count_seen = false;
+ bool init_n2 = SSA_VAR_P (fd->loop.n2) && zero_iter1_bb;
for (i = 0; i < (fd->ordered ? fd->ordered : fd->collapse); i++)
{
tree itype = TREE_TYPE (fd->loops[i].v);
{
gcond *cond_stmt;
tree n1, n2;
+ if (init_n2 && i < fd->collapse && !rect_count_seen)
+ {
+ /* When called with non-NULL zero_iter1_bb, we won't clear
+ fd->loop.n2 in the if (zero_iter_bb == NULL) code below
+ and if it is prior to storing fd->loop.n2 where
+ rect_count_seen is set, it could be used uninitialized.
+ As zero_iter1_bb in that case can be reached also if there
+ are non-zero iterations, the clearing can't be emitted
+ to the zero_iter1_bb, but needs to be done before the
+ condition. */
+ gassign *assign_stmt
+ = gimple_build_assign (fd->loop.n2, build_zero_cst (type));
+ gsi_insert_before (gsi, assign_stmt, GSI_SAME_STMT);
+ init_n2 = false;
+ }
n1 = fold_convert (itype, unshare_expr (fd->loops[i].n1));
n1 = force_gimple_operand_gsi (gsi, n1, true, NULL_TREE,
true, GSI_SAME_STMT);
--- /dev/null
+/* PR middle-end/121453 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -O2 -Wuninitialized" } */
+
+void bar (int, int, int);
+int v[40][40][40];
+
+void
+foo (int x, int y, int z)
+{
+ int i, j, k;
+#pragma omp parallel for simd collapse(3)
+ for (k = 1; k <= z; ++k)
+ for (j = 2; j <= y - 1; ++j)
+ for (i = 1; i <= x; ++i)
+ v[i][j][k] = 0;
+ bar (i, j, k);
+}