https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103039
--- Comment #7 from Tobias Burnus <burnus at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #6) > I think the way to achieve this would be make sure to return true from the > gfc_omp_privatize_by_reference hook. What puzzles me is actually the reverse: class(a), pointer :: x ... select type (x) class is (a) !$omp parallel do default(shared) private(k) reduction(+:s) Looking at the dump, one sees in the gimple dump: #pragma omp parallel private(k) reduction(+:s) default(shared) firstprivate(__tmp_class_a) I think it is okay that __tmp_class_a is firstprivate – but in any case, no deep copy should then be done in gfc_omp_clause_copy_ctor. * * * Regarding why the firstprivate shows up: gfc_omp_predetermined_sharing returns OMP_CLAUSE_DEFAULT_FIRSTPRIVATE because of: /* Associate names preserve the association established during ASSOCIATE. As they are implemented either as pointers to the selector or array descriptor and shouldn't really change in the ASSOCIATE region, this decl can be either shared or firstprivate. If it is a pointer, use firstprivate, as it is cheaper that way, otherwise make it shared. */ if (GFC_DECL_ASSOCIATE_VAR_P (decl)) { if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE) return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE; else return OMP_CLAUSE_DEFAULT_SHARED; } Added in commit r5-1190-g92d28cbb59cc5a611af41342c5b224fbf779a44d * * * BTW, using: firstprivate(x) fails with Error: ASSOCIATE name ‘__tmp_class_a’ in FIRSTPRIVATE clause at (1) While select type (y => x) class is (a) !$omp parallel do default(shared) private(k) reduction(+:s) firstprivate(x) is accepted but while the original dump has 'firstprivate(x)', it is removed (as unused) during gimplify, resulting the output above. Note: Associate names can appear for 'associate', 'select type', 'select rank' and 'change team'. — For 'select type/rank', the selector name is the same as the selector (wihch must be a variable) when left out. * * * OpenMP has for "predetermined data-sharing attributes": "An associate name that may appear in a variable definition context is shared if its association occurs outside of the construct and otherwise it has the same data-sharing attribute as the selector with which it is associated."