Summary: | [11 Regression] Compiler error using gfortran and OpenMP since r5-1190 | ||
---|---|---|---|
Product: | gcc | Reporter: | Marcos Vanella <marcos.vanella> |
Component: | fortran | Assignee: | Jakub Jelinek <jakub> |
Status: | ASSIGNED --- | ||
Severity: | normal | CC: | burnus, jakub, marcos.vanella |
Priority: | P2 | Keywords: | ice-on-valid-code, openmp |
Version: | 13.2.0 | ||
Target Milestone: | 11.5 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2024-04-23 00:00:00 | |
Attachments: |
Fortran Module source to reproduce described error.
gcc14-pr114825.patch |
Description
Marcos Vanella
2024-04-23 13:33:07 UTC
Started with r5-1190-g92d28cbb59cc5a611af41342c5b224fbf779a44d Reduced testcase (just -fopenmp needed): subroutine pr114825(b) type t real, allocatable :: m(:) end type t type(t), allocatable, target :: b(:) type(t), pointer :: d !$omp parallel private(d) d => b(1) !$omp end parallel contains subroutine sub d => b(1) end subroutine sub end subroutine pr114825 The difference between the failing program and a working program (pointer-assignment in 'sub' comment out) is: failing: 'type' in gfc_omp_clause_default_ctor is '<record_type 0x7ffff7004930 t' working: 'type' is '<pointer_type 0x7ffff700a150 ... <record_type 0x7ffff7004930 t' (and 'outer' is NULL in either case) In the caller, i.e. lower_rec_input_clauses: working: p debug_tree(new_var) → <var_decl 0x7ffff720df30 d failing: p debug(new_var) → *d – i.e. with a memory dereference. The reason is that gfc_omp_privatize_by_reference returns true in the omp-low.cc's lower_rec_input_clauses call to it: 5737 else if (omp_privatize_by_reference (var) 5738 && (c_kind != OMP_CLAUSE_FIRSTPRIVATE 5739 || !OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c))) The problem is that: /* Array POINTER/ALLOCATABLE have aggregate types, all user variables that have POINTER_TYPE type and aren't scalar pointers, scalar allocatables, Cray pointees or C pointers are supposed to be privatized by reference. */ if (GFC_DECL_GET_SCALAR_POINTER (decl) || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl) || GFC_DECL_CRAY_POINTEE (decl) || GFC_DECL_ASSOCIATE_VAR_P (decl) || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) return false; fails in the failing case – but works in the non-failing case – IHMO, it should have matched the first item. Yes, and the reason for that is that while in subroutine pr114825(b) type t real, allocatable :: m(:) end type t type(t), allocatable, target :: b(:) type(t), pointer :: d !$omp parallel private(d) d => b(1) !$omp end parallel contains subroutine sub ! d => b(1) end subroutine sub end subroutine pr114825 the d in the private clause is the VAR_DECL created by the Fortran FE with DECL_LANG_SPECIFIC, d in the private clause in the testcase without the d => b(1) commented out is a VAR_DECL created by tree-nested.cc: #5 0x000000000123a64b in build_decl (loc=21312, code=VAR_DECL, name=<identifier_node 0x7fffe9efc118 d>, type=<pointer_type 0x7fffe9f03150>) at ../../gcc/tree.cc:5379 #6 0x0000000000f4f39e in get_local_debug_decl (info=0x3b871d0, decl=<var_decl 0x7fffea137c60 d>, field=<field_decl 0x7fffe9f00720 d>) at ../../gcc/tree-nested.cc:1895 #7 0x0000000000f504c9 in convert_local_omp_clauses (pclauses=0x7fffea134780, wi=0x7fffffffd9b0) at ../../gcc/tree-nested.cc:2157 Perhaps get_local_debug_decl should also copy DECL_LANG_SPECIFIC? Of course, perhaps it might need e.g. DECL_LANG_FLAG_* too. If decl in there is just a VAR_DECL, we might as well just copy_node it and tweak afterwards, but if it is e.g. a PARM_DECL, that wouldn't be possible. Created attachment 58027 [details] gcc14-pr114825.patch Untested fix. The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:14d48516e588ad2b35e2007b3970bdcb1b3f145c commit r14-10130-g14d48516e588ad2b35e2007b3970bdcb1b3f145c Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Apr 25 20:09:35 2024 +0200 openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl copy [PR114825] tree-nested.cc creates in 2 spots artificial VAR_DECLs, one of them is used both for debug info and OpenMP/OpenACC lowering purposes, the other solely for OpenMP/OpenACC lowering purposes. When the decls are used in OpenMP/OpenACC lowering, the OMP langhooks (mostly Fortran, C just a little and C++ doesn't have nested functions) then inspect the flags on the vars and based on that decide how to lower the corresponding clauses. Unfortunately we weren't copying DECL_LANG_SPECIFIC and DECL_LANG_FLAG_?, so the langhooks made decisions on the default flags on those instead. As the original decl isn't necessarily a VAR_DECL, could be e.g. PARM_DECL, using copy_node wouldn't work properly, so this patch just copies those flags in addition to other flags it was copying already. And I've removed code duplication by introducing a helper function which does copying common to both uses. 2024-04-25 Jakub Jelinek <jakub@redhat.com> PR fortran/114825 * tree-nested.cc (get_debug_decl): New function. (get_nonlocal_debug_decl): Use it. (get_local_debug_decl): Likewise. * gfortran.dg/gomp/pr114825.f90: New test. Fixed on the trunk so far. The releases/gcc-13 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:6d30cfc3fc88976151d0d10e73e10111ccb71ee0 commit r13-8730-g6d30cfc3fc88976151d0d10e73e10111ccb71ee0 Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Apr 25 20:09:35 2024 +0200 openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl copy [PR114825] tree-nested.cc creates in 2 spots artificial VAR_DECLs, one of them is used both for debug info and OpenMP/OpenACC lowering purposes, the other solely for OpenMP/OpenACC lowering purposes. When the decls are used in OpenMP/OpenACC lowering, the OMP langhooks (mostly Fortran, C just a little and C++ doesn't have nested functions) then inspect the flags on the vars and based on that decide how to lower the corresponding clauses. Unfortunately we weren't copying DECL_LANG_SPECIFIC and DECL_LANG_FLAG_?, so the langhooks made decisions on the default flags on those instead. As the original decl isn't necessarily a VAR_DECL, could be e.g. PARM_DECL, using copy_node wouldn't work properly, so this patch just copies those flags in addition to other flags it was copying already. And I've removed code duplication by introducing a helper function which does copying common to both uses. 2024-04-25 Jakub Jelinek <jakub@redhat.com> PR fortran/114825 * tree-nested.cc (get_debug_decl): New function. (get_nonlocal_debug_decl): Use it. (get_local_debug_decl): Likewise. * gfortran.dg/gomp/pr114825.f90: New test. (cherry picked from commit 14d48516e588ad2b35e2007b3970bdcb1b3f145c) Fixed also for 13.3. The releases/gcc-12 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:cc96dc569f74b7410a97b4beee16435fc2abcfdd commit r12-10527-gcc96dc569f74b7410a97b4beee16435fc2abcfdd Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Apr 25 20:09:35 2024 +0200 openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl copy [PR114825] tree-nested.cc creates in 2 spots artificial VAR_DECLs, one of them is used both for debug info and OpenMP/OpenACC lowering purposes, the other solely for OpenMP/OpenACC lowering purposes. When the decls are used in OpenMP/OpenACC lowering, the OMP langhooks (mostly Fortran, C just a little and C++ doesn't have nested functions) then inspect the flags on the vars and based on that decide how to lower the corresponding clauses. Unfortunately we weren't copying DECL_LANG_SPECIFIC and DECL_LANG_FLAG_?, so the langhooks made decisions on the default flags on those instead. As the original decl isn't necessarily a VAR_DECL, could be e.g. PARM_DECL, using copy_node wouldn't work properly, so this patch just copies those flags in addition to other flags it was copying already. And I've removed code duplication by introducing a helper function which does copying common to both uses. 2024-04-25 Jakub Jelinek <jakub@redhat.com> PR fortran/114825 * tree-nested.cc (get_debug_decl): New function. (get_nonlocal_debug_decl): Use it. (get_local_debug_decl): Likewise. * gfortran.dg/gomp/pr114825.f90: New test. (cherry picked from commit 14d48516e588ad2b35e2007b3970bdcb1b3f145c) Should be fixed for 12.4+ too. |