https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126950
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:787c7e0c01f091291edeb2471367119ca6f438e7 commit r17-3947-g787c7e0c01f091291edeb2471367119ca6f438e7 Author: Jerry DeLisle <[email protected]> Date: Wed Aug 19 10:33:56 2026 -0700 fortran: [PR126950] Load the span of a span addressed dummy on entry A TARGET assumed-shape dummy is addressed through the span of its descriptor since r17-3342. Its bounds and data pointer are loaded into local variables on entry, but the span was reloaded from the descriptor at each element reference. Inside an outlined region, such as an OpenMP target region, only those local variables are available; the descriptor is not mapped to the device, so the reload dereferenced a host pointer there and the region used a garbage span. Load the span on entry as well, alongside the bounds, and use that variable for element addressing. The variable is created with the dummy's declaration because the procedure body is translated before gfc_trans_dummy_array_bias emits the load. The load is placed in the init block, which is already guarded by the argument being present, so an absent optional dummy is not dereferenced. Assisted-by: Claude Opus 5 PR fortran/126950 gcc/fortran/ChangeLog: * trans.h (struct lang_decl): Add span. (GFC_DECL_SPAN, GFC_DECL_GET_SPAN): New macros. * trans-decl.cc (gfc_build_dummy_array_decl): Create the variable holding the span of a span addressed dummy. * trans-array.cc (gfc_trans_dummy_array_bias): Load it from the descriptor on entry. (gfc_get_array_span): Use it. * trans.cc (get_array_span): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/c_loc_test_22.f90: Update dump patterns for the span being loaded on entry. * gfortran.dg/gomp/target-span-1.f90: New test.
