Created attachment 50622 [details] Fortran code showing problem Hi All! Pointer association is lost when compiling with -O1 or -O2, curiously not with -O3 unless -fcheck=recursion is used Seen on: GNU Fortran (GCC) 11.0.1 20210417 (experimental) GNU Fortran (GCC) 10.3.1 20210417 GNU Fortran (GCC) 9.3.1 20210417 Thank you very much. Best regards, José Rui
Patch posted https://gcc.gnu.org/pipermail/fortran/2021-April/055946.html
Confirmed since at least GCC7.
(In reply to José Rui Faustino de Sousa from comment #1) > Patch posted > > https://gcc.gnu.org/pipermail/fortran/2021-April/055946.html The patch is technically fine and regtests ok, but was unfortunately never reviewed. The basic fix can be slightly shortened to: diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc index 0ea7c74a6f1..c062a5b29d7 100644 --- a/gcc/fortran/trans-types.cc +++ b/gcc/fortran/trans-types.cc @@ -3054,12 +3054,23 @@ create_fn_spec (gfc_symbol *sym, tree fntype) for (f = gfc_sym_get_dummy_args (sym); f; f = f->next) if (spec_len < sizeof (spec)) { - if (!f->sym || f->sym->attr.pointer || f->sym->attr.target + bool is_class = false; + bool is_pointer = false; + + if (f->sym) + { + is_class = f->sym->ts.type == BT_CLASS && CLASS_DATA (f->sym) + && f->sym->attr.class_ok; + is_pointer = is_class ? CLASS_DATA (f->sym)->attr.class_pointer + : f->sym->attr.pointer; + } + + if (f->sym == NULL || is_pointer || f->sym->attr.target || f->sym->attr.external || f->sym->attr.cray_pointer || (f->sym->ts.type == BT_DERIVED && (f->sym->ts.u.derived->attr.proc_pointer_comp || f->sym->ts.u.derived->attr.pointer_comp)) - || (f->sym->ts.type == BT_CLASS + || (is_class && (CLASS_DATA (f->sym)->ts.u.derived->attr.proc_pointer_comp || CLASS_DATA (f->sym)->ts.u.derived->attr.pointer_comp)) || (f->sym->ts.type == BT_INTEGER && f->sym->ts.is_c_interop)) I can take care of it for you.
Pinged here: https://gcc.gnu.org/pipermail/fortran/2022-September/058212.html
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:be60aa5b608b5f09fadfeff852a46589ac311a42 commit r13-2743-gbe60aa5b608b5f09fadfeff852a46589ac311a42 Author: José Rui Faustino de Sousa <jrfsousa@gmail.com> Date: Mon Sep 19 22:00:45 2022 +0200 Fortran: Fix function attributes [PR100132] gcc/fortran/ChangeLog: PR fortran/100132 * trans-types.cc (create_fn_spec): Fix function attributes when passing polymorphic pointers. gcc/testsuite/ChangeLog: PR fortran/100132 * gfortran.dg/PR100132.f90: New test.
The releases/gcc-12 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:9de83c0939dabdbefcb88dfef3ad7caf932951ec commit r12-8802-g9de83c0939dabdbefcb88dfef3ad7caf932951ec Author: José Rui Faustino de Sousa <jrfsousa@gmail.com> Date: Mon Sep 19 22:00:45 2022 +0200 Fortran: Fix function attributes [PR100132] gcc/fortran/ChangeLog: PR fortran/100132 * trans-types.cc (create_fn_spec): Fix function attributes when passing polymorphic pointers. gcc/testsuite/ChangeLog: PR fortran/100132 * gfortran.dg/PR100132.f90: New test. (cherry picked from commit be60aa5b608b5f09fadfeff852a46589ac311a42)
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:cd13cc012e0bca927f97f618ab54c8d365883bbc commit r11-10286-gcd13cc012e0bca927f97f618ab54c8d365883bbc Author: José Rui Faustino de Sousa <jrfsousa@gmail.com> Date: Mon Sep 19 22:00:45 2022 +0200 Fortran: Fix function attributes [PR100132] gcc/fortran/ChangeLog: PR fortran/100132 * trans-types.c (create_fn_spec): Fix function attributes when passing polymorphic pointers. gcc/testsuite/ChangeLog: PR fortran/100132 * gfortran.dg/PR100132.f90: New test. (cherry picked from commit be60aa5b608b5f09fadfeff852a46589ac311a42)
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:8c583871e70f5530907d22a21b0f1d1e7b90e224 commit r10-11015-g8c583871e70f5530907d22a21b0f1d1e7b90e224 Author: José Rui Faustino de Sousa <jrfsousa@gmail.com> Date: Mon Sep 19 22:00:45 2022 +0200 Fortran: Fix function attributes [PR100132] gcc/fortran/ChangeLog: PR fortran/100132 * trans-types.c (create_fn_spec): Fix function attributes when passing polymorphic pointers. gcc/testsuite/ChangeLog: PR fortran/100132 * gfortran.dg/PR100132.f90: New test. (cherry picked from commit be60aa5b608b5f09fadfeff852a46589ac311a42)
Fixed on all open branches. Closing. Thanks for the patch!
*** Bug 87659 has been marked as a duplicate of this bug. ***