@@ -13725,7 +13725,7 @@ gimplify_omp_loop (tree *expr_p, gimple_
*pc = NULL_TREE;
*expr_p = t;
}
- return gimplify_omp_for (expr_p, pre_p);
+ return gimplify_expr (expr_p, pre_p, NULL, is_gimple_stmt, fb_none);
}
@@ -15479,8 +15479,19 @@ gimplify_expr (tree *expr_p, gimple_seq
ret = GS_ALL_DONE;
break;
- case OMP_FOR:
case OMP_SIMD:
+ {
+ /* Temporarily disable into_ssa, as scan_omp_simd
+ which calls copy_gimple_seq_and_replace_locals can't deal
+ with SSA_NAMEs defined outside of the body properly. */
+ bool saved_into_ssa = gimplify_ctxp->into_ssa;
+ gimplify_ctxp->into_ssa = false;
+ ret = gimplify_omp_for (expr_p, pre_p);
+ gimplify_ctxp->into_ssa = saved_into_ssa;
+ break;
+ }
+
+ case OMP_FOR:
case OMP_DISTRIBUTE:
case OMP_TASKLOOP:
case OACC_LOOP:
@@ -0,0 +1,19 @@
+! PR middle-end/104757
+! { dg-do compile }
+! { dg-options "-O -fopenmp" }
+
+module pr104757
+ implicit none (external, type)
+ integer :: ll
+ !$omp declare target (ll)
+contains
+ subroutine foo (i1)
+ !$omp declare target (foo)
+ logical :: i1
+ integer :: i
+ !$omp distribute simd if(i1)
+ do i = 1, 64
+ ll = ll + 1
+ end do
+ end
+end module
@@ -0,0 +1,14 @@
+/* PR middle-end/104757 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp" } */
+
+#pragma omp declare target
+void
+foo (int x, int y, int *z)
+{
+ int j = 0;
+ #pragma omp simd linear(j:x + y)
+ for (int i = 0; i < 64; i++)
+ j += x + y;
+}
+#pragma omp end declare target