[PATCH][regression][OpenMP][PR120286] Double free detected when using openmp

Jerry D jvdelisle2@gmail.com
Fri Mar 13 04:43:33 GMT 2026


The attached patch fixes this regression. I would like further review on this.
It looks OK and regression tests on x86_64. I also confirmed the segfault when 
running before the patch.

OK for mainline and later backports.

Regards,

Jerry

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.

gcc/testsuite/ChangeLog:

	PR fortran/120286
	* gfortran.dg/pr120286.f90: New test.

Signed-off-by: Christopher Albert <albert@tugraz.at>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr120286.diff
Type: text/x-patch
Size: 7303 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20260312/3844c447/attachment-0001.bin>


More information about the Fortran mailing list