[Bug fortran/126950] New: [17 Regression] Wrong code issues with libgomp.fortran/use_device_addr-1.f90 since r17-3342-gf3943597388db4

"burnus at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126950

            Bug ID: 126950
           Summary: [17 Regression] Wrong code issues with
                    libgomp.fortran/use_device_addr-1.f90 since
                    r17-3342-gf3943597388db4
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

Since r17-3342-gf3943597388db4 (cf. also PR 126940). the following testcases
fail with OpenMP offloading to an Nvidia GPU [nvptx] (but oddly not to an AMD
GPU [gcn]).

The testcases are believed to be valid.


PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-1.f90
  -O1  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-1.f90
  -O2  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-1.f90
  -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer
-finline-functions  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-1.f90
  -O3 -g  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-1.f90
  -Os  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-2.f90
  -O0  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-2.f90
  -O1  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-2.f90
  -O2  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-2.f90
  -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer
-finline-functions  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-2.f90
  -O3 -g  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-2.f90
  -Os  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-3.f90
  -O0  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-3.f90
  -O1  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-3.f90
  -O2  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-3.f90
  -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer
-finline-functions  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-3.f90
  -O3 -g  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-3.f90
  -Os  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-4.f90
  -O0  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-4.f90
  -O1  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-4.f90
  -O2  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-4.f90
  -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer
-finline-functions  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-4.f90
  -O3 -g  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_addr-4.f90
  -Os  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-1.f90 
 -O0  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-1.f90 
 -O1  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-1.f90 
 -O2  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-1.f90 
 -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer
-finline-functions  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-1.f90 
 -O3 -g  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-1.f90 
 -Os  execution test
PASS -> FAIL: qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-3.f90 
 -O  execution test
PASS -> FAIL:
qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-optional-3.f90   -O0
 execution test
PASS -> FAIL:
qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-optional-3.f90   -O1
 execution test
PASS -> FAIL:
qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-optional-3.f90   -O2
 execution test
PASS -> FAIL:
qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-optional-3.f90   -O3
-fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions 
execution test
PASS -> FAIL:
qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-optional-3.f90   -O3
-g  execution test
PASS -> FAIL:
qemu-rtx4080-02/libgomp.sum:libgomp.fortran/use_device_ptr-optional-3.f90   -Os
 execution test

* * *

It fails as follows:

$ gfortran -fopenmp -Wno-deprecated-openmp
libgomp/testsuite/libgomp.fortran/use_device_addr-1.f90  -g
$ LD_LIBRARY_PATH=$HOME/projects-local/gcc-trunk-offload/lib64 ltrace ./a.out
GOMP_offload_register_ver(0x40001, 0x40c780, 5, 0x502840)                      
                                                                              
= 1
GOMP_offload_register_ver(0x40003, 0x40c780, 8, 0x502980)                      
                                                                              
= 1
_gfortran_set_args(1, 0x7ffc7cab6a78, 0x7ffc7cab6a78, 0x504db0)                
                                                                              
= 1
_gfortran_set_options(7, 0x40c670, 0x7ffc7cab6a78, 0x504db0)                   
                                                                              
= 0
malloc(8)                                                                      
                                                                              
= 0x2e021e40
malloc(8)                                                                      
                                                                              
= 0x2e021e60
malloc(8)                                                                      
                                                                              
= 0x2e021e80
malloc(8)                                                                      
                                                                              
= 0x2e021ea0
GOMP_target_data_ext(0xffffffff, 4, 0x7ffc7cab6890, 0x505e00)                  
                                                                              
= 0x2ee0b440
GOMP_target_ext(0xffffffff, 0x40b28d, 16, 0x7ffc7cab2860 <no return ...>
--- SIGSEGV (Segmentation fault) ---

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7fe8def61def in ???
        at ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
#1  0x7fe8df084bc0 in __memmove_avx_unaligned_erms
        at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:364
#2  0x7fe8df179413 in gomp_map_vars_internal
        at /net/vbuild-02/srv/data/tburnus/repos/gcc/libgomp/target.c:2063
#3  0x7fe8df179413 in gomp_map_vars
        at /net/vbuild-02/srv/data/tburnus/repos/gcc/libgomp/target.c:2266
#4  0x7fe8df17fe00 in GOMP_target_ext
        at /net/vbuild-02/srv/data/tburnus/repos/gcc/libgomp/target.c:3691
#5  0x401540 in do_offload_scalar
        at libgomp/testsuite/libgomp.fortran/use_device_addr-1.f90:81
#6  0x40173e in __target_procs_MOD_copy3_scalar
        at libgomp/testsuite/libgomp.fortran/use_device_addr-1.f90:75
#7  0x40ad98 in __tests_MOD_test_main_1
        at libgomp/testsuite/libgomp.fortran/use_device_addr-1.f90:1045
#8  0x40b21c in omp_device_addr
        at libgomp/testsuite/libgomp.fortran/use_device_addr-1.f90:1253
#9  0x40b285 in main
        at libgomp/testsuite/libgomp.fortran/use_device_addr-1.f90:1245
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++

* * *

commit f3943597388db4846386b6d5a18d33ebf80ea96c
Author:     Jerry DeLisle <[email protected]>
AuthorDate: Mon Aug 10 09:37:01 2026 -0700
Commit:     Jerry DeLisle <[email protected]>
CommitDate: Mon Aug 17 13:06:41 2026 -0700

    fortran: [PR53800] Wrong copy-in/out with array actual to TARGET dummy

    An actual argument whose elements are spaced by more than the element
    size - a CLASS array, or a component of a derived-type array - was
    copied in and out when passed to a TARGET or POINTER dummy, so pointers
    associated with the dummy went stale on return.

    Such an actual argument is now passed with a descriptor of its own,
    whose element type is that of the subobject and whose span is the
    element size of the array, as is already done for a pointer assignment
    to a subobject of an array.  The dummy addresses its elements through
    that span.  Passing it on to a dummy that requires contiguous storage
    copies it, but only if it turns out not to be contiguous.

            PR fortran/53800

    gcc/fortran/ChangeLog:

            * gfortran.h (gfc_is_span_addressed_dummy): New prototype.
            * symbol.cc (gfc_is_span_addressed_dummy): New function.
            * expr.cc (is_subref_array): Return true for a span addressed
dummy.
            * trans.h (gfc_get_span_descriptor): New prototype.
            * trans.cc (gfc_get_span_descriptor): New function returning the
            descriptor that carries a pointer array decl's span.
            (get_array_span): Use it, including for character types.
            * trans-array.cc (is_pointer_array): Note in the comment that the
            tree must be a descriptor.
            (span_addressed_array): New function returning the decl that
            provides the span of an array.
            (gfc_get_array_span): Use it.
            (gfc_conv_scalarized_array_ref, gfc_conv_array_ref): Likewise, so
            that a descriptorless dummy is addressed by its span.
            (gfc_get_dataptr_offset): Likewise and dereference a spanned
            character element.
            (gfc_conv_expr_descriptor): Describe a subobject of the array
            elements by a new descriptor when no temporary is made.
            * trans-decl.cc (gfc_build_dummy_array_decl): Use
            gfc_is_span_addressed_dummy to mark the dummy as a pointer array.
            (gfc_get_symbol_decl): Likewise.
            * trans-expr.cc (is_subobject_ref): New function.
            (copy_in_out_allowed): Take the actual argument.  Use
            gfc_is_span_addressed_dummy and keep the copy for an actual
            argument with a vector subscript.
            (gfc_conv_gfc_desc_to_cfi_desc): Remove the now duplicate
offsetting
            of the data pointer for a subobject reference.
            (gfc_class_array_data_assign): Also copy the span field.
            (gfc_conv_procedure_call): Use copy_in_out_allowed to skip
            copy-in/copy-out for a class array reference, a class array
function
            result and a subref array.  Pass a spanned descriptor instead and
            make the copy of a span addressed dummy conditional on it not being
            contiguous.
            * trans-intrinsic.cc (gfc_conv_is_contiguous_expr): Check the span
            of a span addressed dummy against the element length.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/c_loc_test_22.f90: Update dump patterns for span
            addressing.
            * gfortran.dg/class_to_type_5.f90: New test.
            * gfortran.dg/class_to_type_6.f90: New test.
            * gfortran.dg/class_to_type_7.f90: New test.
            * gfortran.dg/class_to_type_8.f90: New test.
            * gfortran.dg/class_to_type_9.f90: New test.

    libgomp/ChangeLog:

            * testsuite/libgomp.oacc-fortran/host_data-5.F90: Update the
            privatization notes for the packing of a TARGET dummy.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.