[Patch] Fortran/openmp: Fix '!$omp end'

Jakub Jelinek jakub@redhat.com
Fri Nov 12 16:07:54 GMT 2021


On Fri, Nov 12, 2021 at 04:56:37PM +0100, Tobias Burnus wrote:
> Fortran/openmp: Fix '!$omp end'
> 
> gcc/fortran/ChangeLog:
> 
> 	* parse.c (decode_omp_directive): Fix permitting 'nowait' for some
> 	combined directives, add missing 'omp end ... loop'.
> 	(gfc_ascii_statement): Fix ST_OMP_END_TEAMS_LOOP result.
> 	* openmp.c (resolve_omp_clauses): Add missing combined loop constructs
> 	case values to the 'if(directive-name: ...)' check.
> 	* trans-openmp.c (gfc_split_omp_clauses): Put nowait on target if
> 	first leaf construct accepting it.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gfortran.dg/gomp/unexpected-end.f90: Update dg-error.
> 	* gfortran.dg/gomp/clauses-1.f90: New test.
> 	* gfortran.dg/gomp/nowait-2.f90: New test.
> 	* gfortran.dg/gomp/nowait-3.f90: New test.

Mostly good, except:

> @@ -6132,10 +6134,9 @@ gfc_split_omp_clauses (gfc_code *code,
>     if (mask & GFC_OMP_MASK_TEAMS && innermost != GFC_OMP_MASK_TEAMS)
>       gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TEAMS],
>  				code->ext.omp_clauses, false, false);
> -   if (((mask & (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> -	== (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> -       && !is_loop)
> -    clausesa[GFC_OMP_SPLIT_DO].nowait = true;
> +   if ((mask & (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> +       == (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> +    clausesa[GFC_OMP_SPLIT_DO].nowait = false;
>  }

this.  In the standard, yes, for parallel {do,sections,workshare}
indeed the do/sections/workshare doesn't get nowait (either
it is not allowed to specify it at all, or if combined with
target, nowait should go to target and nothing else).
But, for the middle-end, we actually want nowait true
whenever a worksharing construct is combined with parallel,
because when the worksharing construct ends, doing a barrier there
will mean we wait, then immediately get to the implicit barrier at the end
of parallel.

c_omp_split_clauses does:
  /* Add implicit nowait clause on
     #pragma omp parallel {for,for simd,sections}.  */
  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
    switch (code)
      {
      case OMP_FOR:
      case OMP_SIMD:
        if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
          cclauses[C_OMP_CLAUSE_SPLIT_FOR]
            = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
        break;
      case OMP_SECTIONS:
        cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]
          = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
        break;
      default:
        break;
      }
and I think the previous code did exactly that.

So, the patch is ok for trunk without the above hunk.

	Jakub



More information about the Gcc-patches mailing list