From 8268c8256dd430174e89142be9ee77b036d6310d Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Mon, 17 Feb 2025 22:52:34 +0100 Subject: OpenMP/Fortran: extend 'adjust_args' clause, fixes for it and declare variant [PR115271] On the extension side, it implements OpenMP 6.0's numeric values/ranges for the adjust_args arguments, including 'omp_num_args'. And it adds parser support for need_device_addr. It also implements the post-OpenMP-6.0 clarification of OpenMP spec Issue #4443 regarding type(c_ptr) with dimension being invalid for need_device_ptr. To be done: Adding full support for need_device_addr (optional, array descriptor, ...). On the invalid side, it removed a bogus c_ptr check that went through all adjust_args without checking for need_device_ptr and the current scope. And it finally also processes 'declare variant' in an INTERFACE block, which is part of PR115271, but it does not handle .mod file yet - the main issue tracked in that PR. PR fortran/115271 gcc/fortran/ChangeLog: * gfortran.h (gfc_omp_namelist): Change need_device_ptr to adj_args union and add more flags. * openmp.cc (gfc_match_omp_declare_variant, gfc_resolve_omp_declare): For adjust_args, handle need_device_addr and numeric values/ranges besides dummy argument names. (resolve_omp_dispatch): Remove bogus a adjust_args check. * trans-decl.cc (gfc_handle_omp_declare_variant): New. (gfc_generate_module_vars, gfc_generate_function_code): Call it. * trans-openmp.cc (gfc_trans_omp_declare_variant): Handle numeric values/ranges besides dummy argument names. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/adjust-args-1.f90: Update dg-.* expectations. * gfortran.dg/gomp/adjust-args-2.f90: Likewise. * gfortran.dg/gomp/adjust-args-2a.f90: Likewise. * gfortran.dg/gomp/adjust-args-3.f90: Likewise. * gfortran.dg/gomp/adjust-args-4.f90: Remove array from c_ptr. * gfortran.dg/gomp/adjust-args-5.f90: Likewise. * gfortran.dg/gomp/adjust-args-11.f90: Likewise. Add check that INTERFACE is now handled in subroutines and in modules. * gfortran.dg/gomp/adjust-args-13.f90: New test. * gfortran.dg/gomp/adjust-args-14.f90: New test. * gfortran.dg/gomp/adjust-args-15.f90: New test. * gfortran.dg/gomp/declare-variant-21.f90: New test. --- gcc/fortran/trans-decl.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'gcc/fortran/trans-decl.cc') diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index 0acf0e9..ebb63a4 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -6131,6 +6131,19 @@ create_module_nml_decl (gfc_symbol *sym) } } +static void +gfc_handle_omp_declare_variant (gfc_symbol * sym) +{ + if (sym->attr.external + && sym->formal_ns + && sym->formal_ns->omp_declare_variant) + { + gfc_namespace *ns = gfc_current_ns; + gfc_current_ns = sym->ns; + gfc_get_symbol_decl (sym); + gfc_current_ns = ns; + } +} /* Generate all the required code for module variables. */ @@ -6155,6 +6168,11 @@ gfc_generate_module_vars (gfc_namespace * ns) if (flag_coarray == GFC_FCOARRAY_LIB && has_coarray_vars_or_accessors) generate_coarray_init (ns); + /* For OpenMP, ensure that declare variant in INTERFACE is is processed + especially as some late diagnostic is only done on tree level. */ + if (flag_openmp) + gfc_traverse_ns (ns, gfc_handle_omp_declare_variant); + cur_module = NULL; gfc_trans_use_stmts (ns); @@ -8005,6 +8023,11 @@ gfc_generate_function_code (gfc_namespace * ns) gfc_conv_cfi_to_gfc (&init, &cleanup, tmp, desc, fsym); } + /* For OpenMP, ensure that declare variant in INTERFACE is is processed + especially as some late diagnostic is only done on tree level. */ + if (flag_openmp) + gfc_traverse_ns (ns, gfc_handle_omp_declare_variant); + gfc_generate_contained_functions (ns); has_coarray_vars_or_accessors = caf_accessor_head != NULL; -- cgit v1.1