https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120286
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-13 branch has been updated by Paul Thomas <[email protected]>: https://gcc.gnu.org/g:fb12014c4ea9967aab463524f283454ce16d9785 commit r13-10241-gfb12014c4ea9967aab463524f283454ce16d9785 Author: Paul Thomas <[email protected]> Date: Thu Apr 2 15:51:01 2026 +0100 Subject: [PATCH] fortran: Preserve scalar class pointers in OpenMP privatization [PR120286] OpenMP privatization currently treats scalar class pointers like owned polymorphic class objects. In the worker cleanup for private/firstprivate class pointers, the generated code finalizes and frees ptr._data even though the clause only copied pointer association status from a shared target. Fix this in gfc_omp_clause_copy_ctor and gfc_omp_clause_dtor by unwrapping saved descriptors first and by recognizing class-pointer container types locally in those hooks. That keeps scalar class pointers on the association-only path without changing the broader polymorphic mapping classification used for OpenMP warnings and deep mapping. Add a runtime regression test for the original private(ptr) crash plus a firstprivate(ptr) association check. gcc/fortran/ChangeLog: PR fortran/120286 * trans-openmp.cc (gfc_is_class_pointer_type): New helper. (gfc_omp_clause_copy_ctor): Unwrap saved descriptors before deciding whether privatization should preserve only pointer association. Handle scalar class pointers on that path too. (gfc_omp_clause_dtor): Likewise. libgomp/ChangeLog: * testsuite/libgomp.fortran/pr120286.f90: New test. Signed-off-by: Christopher Albert <[email protected]> (cherry picked from commit 86960a3ffbd7d87b6b1d18d7cc02bf5078526bca)
