Hi! As the testcase shows, we need to gimplify OMP_CLAUSE_SIZE, so that we don't end up with SAVE_EXPR or anything similar non-gimple in it.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2021-06-08 Jakub Jelinek <ja...@redhat.com> PR fortran/100965 * trans-openmp.c (gfc_omp_finish_clause): Gimplify OMP_CLAUSE_SIZE. * gfortran.dg/gomp/pr100965.f90: New test. --- gcc/fortran/trans-openmp.c.jj 2021-06-08 11:23:45.704331441 +0200 +++ gcc/fortran/trans-openmp.c 2021-06-08 16:28:09.433635685 +0200 @@ -1639,6 +1639,9 @@ gfc_omp_finish_clause (tree c, gimple_se OMP_CLAUSE_SIZE (c) = DECL_P (decl) ? DECL_SIZE_UNIT (decl) : TYPE_SIZE_UNIT (TREE_TYPE (decl)); + if (gimplify_expr (&OMP_CLAUSE_SIZE (c), pre_p, + NULL, is_gimple_val, fb_rvalue) == GS_ERROR) + OMP_CLAUSE_SIZE (c) = size_int (0); if (c2) { OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (last); --- gcc/testsuite/gfortran.dg/gomp/pr100965.f90.jj 2021-06-08 16:33:29.701355827 +0200 +++ gcc/testsuite/gfortran.dg/gomp/pr100965.f90 2021-06-08 16:33:07.876647478 +0200 @@ -0,0 +1,16 @@ +! PR fortran/100965 +! { dg-do compile } + +implicit none + character(len=:), allocatable :: s + logical :: l + !$omp target map(from: l) + l = allocated (s) + !$omp end target + if (l) stop 1 + + !$omp target map(from: l) + l = allocated (s) + !$omp end target + if (l) stop 2 +end Jakub