OffTarget

Observed issues › nested/gcc-fortran-root-and-element-pointer-components-ice

Appears to behave incorrectlyCompiler crash · Fortran · OpenMP · Open

GCC Fortran: compiler crash on root and element pointer components in one map list

Legality: not independently confirmed. Independent readings are uncertain: Whether map(to: r) maps the allocated allocatable component nx and its elements, so that the later maps of r%nx(1)%a and r%nx(2)%a attach correctly, is not settled by the text; the allocatable-component rule only says the map may treat allocation status as unallocated. An ICE is undesirable but a required result cannot be established. How this is checked

GCC crashes in gimplify_adjust_omp_clauses on a root pointer component and element pointer components in one map list.

Affected variants

CompilerMI300A gfx942
unified memory (XNACK 1)
MI300A gfx942
copy (XNACK 0)
MI250X gfx90a
copy (XNACK 0)
MI300X gfx942
copy (XNACK 0)
MI350X gfx950
copy (XNACK 0)
A100 sm_80
separate memory
A100 sm_80
managed memory
AFAR 24.3.0correctcorrectunknown
not run
correctcorrectn/an/a
CCE 19.0.0correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 20.0.2correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.3correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.4correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/afails another waycorrect
NVHPC 26.9n/an/an/an/an/afails another waycorrect
GCC 16.2.0behaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlyn/a

"behaves incorrectly" / "not supported": this issue, confirmed in up to four environments (another build directory, another node, a repeat). "fails another way": a different failure, not counted as this issue. "unknown": not run there, or the runs disagree.

Messages

ResultCompiler and GPUMessage
behaves incorrectlyGCC 16.2.0, MI300A unified
GCC 16.2.0, MI300A copy
show
site-nested--gcc-fortran-root-and-element-pointer-components-ice.f90:61:76:
   61 |   !$omp target enter data map(to: r%a) map(to: r%nx(1)%a) map(to: r%nx(2)%a)
      |                                                                            ^
internal compiler error: in gimplify_adjust_omp_clauses, at gimplify.cc:16128
0x2072e2d internal_error(char const*, ...)
	<dir>:787
0x7d943f fancy_abort(char const*, int, char const*)
	<dir>:1813
behaves incorrectlyGCC 16.2.0, MI250X
show
site-nested--gcc-fortran-root-and-element-pointer-components-ice.f90:56:76:
   56 |   !$omp target enter data map(to: r%a) map(to: r%nx(1)%a) map(to: r%nx(2)%a)
      |                                                                            ^
internal compiler error: in gimplify_adjust_omp_clauses, at gimplify.cc:16128
0x2072e2d internal_error(char const*, ...)
	<dir><host>-gcc-src/gcc-16.2.0/gcc/diagnostic-global-context.cc:787
0x7d943f fancy_abort(char const*, int, char const*)
	<dir><host>-gcc-src/gcc-16.2.0/gcc/diagnostics/context.cc:1813
behaves incorrectlyGCC 16.2.0, MI300X
GCC 16.2.0, MI350X
show
site-nested--gcc-fortran-root-and-element-pointer-components-ice.f90:61:76:
   61 |   !$omp target enter data map(to: r%a) map(to: r%nx(1)%a) map(to: r%nx(2)%a)
      |                                                                            ^
internal compiler error: in gimplify_adjust_omp_clauses, at gimplify.cc:16128
0x2083fcd internal_error(char const*, ...)
	<home>/<user>/gcc-work/gcc-16.2.0/gcc/diagnostic-global-context.cc:787
0x7cebc6 fancy_abort(char const*, int, char const*)
	<home>/<user>/gcc-work/gcc-16.2.0/gcc/diagnostics/context.cc:1813
behaves incorrectlyGCC 16.2.0, A100 separate
show
site-nested--gcc-fortran-root-and-element-pointer-components-ice.f90:56:76:
   56 |   !$omp target enter data map(to: r%a) map(to: r%nx(1)%a) map(to: r%nx(2)%a)
      |                                                                            ^
internal compiler error: in gimplify_adjust_omp_clauses, at gimplify.cc:16128
0x214aceb internal_error(char const*, ...)
	<home>/gcc-build/gcc-16.2.0/gcc/diagnostic-global-context.cc:787
0x7db5a3 fancy_abort(char const*, int, char const*)
	<home>/gcc-build/gcc-16.2.0/gcc/diagnostics/context.cc:1813
fails another wayNVHPC 25.11, A100 separate
NVHPC 26.9, A100 separate
show
Failing in Thread:1
Accelerator Fatal Error: call to cuMemcpyDtoHAsync returned error 700 (CUDA_ERROR_ILLEGAL_ADDRESS): Illegal address during kernel execution
 File: <dir>
 Function: t:31
 Line: 59

Reproduce

GCC 16.2.0, MI300A unified

export LD_LIBRARY_PATH=$GCC_16_2/lib64:/opt/rocm-7.2.1/lib
$GCC_16_2/bin/gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

GCC 16.2.0, A100 separate

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=$GCC_16_2/lib64
$GCC_16_2/bin/gfortran -fopenmp -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 repro.f90 -o repro
OMP_TARGET_OFFLOAD=mandatory ./repro

AFAR 24.3.0, MI300A unified (runs correctly)

$AFAR/bin/amdflang -fopenmp --offload-arch=gfx942 -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (70 lines)
! # Finding (nested-data): GCC ICE in gimplify_adjust_omp_clauses: a pointer component of the root and the pointer components
! # of the elements of an allocatable component array in one map list
!
! - toolchains and modes that fail: gcc_g90 (GCC 16.2.0), gcc_sm80 (GCC 16.2.0); modes: copy; -O2
! - build: gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx90a -O2 (gcc_g90); gfortran -fopenmp
!   -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 (gcc_sm80)
! - failure: ice
! - observed: `Please submit a full bug report, with preprocessed source (by using -freport-bug).`; identical signature on 2 of 2
!   failing cells
! - expected: compiles and prints `tot= 24` with `check=pass`
! - rule: pointer components are list items when they appear in a map clause ("The list items that appear in a map
!   clause may include array sections and structure elements", 5.2 §5.8.3 p.151 l.13); the construct names a pointer
!   component of the root and the pointer components of the elements of an allocatable array component, none of them the
!   base pointer of another item (5.2 §5.8.3 p.152 l.1-3)
! - same-compiler control: controls/g5-ctl-element-pointers-only.f90 (one change from this file; correct on gcc_g90 (GCC 16.2.0),
!   gcc_sm80 (GCC 16.2.0); rows results/nested/red/gate_abd.jsonl, results/nested/red/gate_c.jsonl, results/nested/red/red3.jsonl,
!   results/nested/red/tuo7.jsonl, results/nested/red/wgs.jsonl, results/nested/red/wnv.jsonl);
!   controls/g5-ctl-root-pointer-only.f90 (one change from this file; correct on gcc_g90 (GCC 16.2.0), gcc_sm80 (GCC 16.2.0); rows
!   results/nested/red/gate_abd.jsonl, results/nested/red/gate_c.jsonl, results/nested/red/red3.jsonl,
!   results/nested/red/tuo7.jsonl, results/nested/red/wgs.jsonl, results/nested/red/wnv.jsonl)
! - other families: afar (AFAR 24.3.0), cce19 (CCE 19.0.0), cce20 (CCE 20.0.2), cce21 (CCE 21.0.3), cce21_4 (CCE 21.0.4), nvhpc
!   (NVHPC 25.11), nvhpc269 (NVHPC 26.9) run the file correctly in managed mode (rows results/nested/red/tuo7.jsonl,
!   results/nested/red/wnv.jsonl, site rows, check case site-nested--gcc-fortran-root-and-element-pointer-components-ice); nvhpc
!   (NVHPC 25.11), nvhpc269 (NVHPC 26.9) fail it another way in copy mode, e.g. `Failing in Thread:1`
! - gate and confirmer: campaign gate of the programs below: 4 cells, 4 confirmed in the four environments (a-d; (c) on another node
!   or GPU; rows results/nested/main/gate_reruns.part.<host>.2711328.jsonl,
!   results/nested/main/gate_reruns.part.<host>.351539.jsonl,
!   results/nested/main/gate_reruns.part.wingtip.3374144.jsonl,
!   results/nested/main/gate_reruns.part.wingtip.3386107.jsonl,
!   results/nested/main/gate_reruns.part.wingtip.3582436.jsonl,
!   results/nested/main/gate_reruns.part.wingtip.3637854.jsonl,
!   results/nested/main/rows.part.<host>.2691037.jsonl, results/nested/main/rows.part.wingtip.3363229.jsonl,
!   results/nested/main/rows.part.wingtip.3363230.jsonl)
! - programs (2): nd-f-omp-tdata_nested-chain-d3-0fae50d2, nd-f-omp-tdata_nested-chain-d3-b0edb43f
! - legality: the rules (offload.engine.rules) accept it and AFAR's flang front end accepts it
program t
  use omp_lib
  implicit none
  type :: n1
    integer, pointer :: a(:) => null()
  end type n1
  type :: n0
    integer, pointer :: a(:) => null()
    type(n1), allocatable :: nx(:)
  end type n0
  type(n0) :: r
  integer :: q, hf, tot
  logical :: ok
  hf = 1
  !$omp target map(from: hf)
  hf = merge(1, 0, omp_is_initial_device())
  !$omp end target
  allocate(r%nx(2))
  allocate(r%a(4))
  allocate(r%nx(1)%a(4))
  allocate(r%nx(2)%a(4))
  r%a = 1
  r%nx(1)%a = 2
  r%nx(2)%a = 3
  !$omp target enter data map(to: r)
  !$omp target enter data map(to: r%a) map(to: r%nx(1)%a) map(to: r%nx(2)%a)
  !$omp target map(tofrom: tot)
    tot = sum(r%nx(1)%a) + sum(r%nx(2)%a) + sum(r%a)
  !$omp end target
  !$omp target exit data map(release: r%a) map(release: r%nx(1)%a) map(release: r%nx(2)%a)
  !$omp target exit data map(release: r)
  ok = tot == 24
  print '(a,i0)', 'tot= ', tot
  print '(a,i0,a,a)', 'RESULT ran_on_host=', hf, ' check=', merge('pass', 'fail', ok)
end program t

Source in the repository

Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page

Expected and observed

Observed where it behaves incorrectly

site-nested--gcc-fortran-root-and-element-pointer-components-ice.f90:61:76:
   61 |   !$omp target enter data map(to: r%a) map(to: r%nx(1)%a) map(to: r%nx(2)%a)
      |                                                                            ^
internal compiler error: in gimplify_adjust_omp_clauses, at gimplify.cc:16128
0x2072e2d internal_error(char const*, ...)
	<dir>:787
0x7d943f fancy_abort(char const*, int, char const*)
	<dir>:1813

What the specification requires

The specification text this program relies on and the compiler is expected to support.

OpenMP 5.2 §5.8.3 p.151 l.13

The list items that appear in a map clause may include array sections and structure elements

OpenMP 5.2 §5.8.3 p.152 l.1-3

Evidence

Same compiler, one change

  • one change from the finding; correct on gcc_g90, gcc_sm80: not run yet
    Control program
    ! control: the element pointers only
    program t
      use omp_lib
      implicit none
      type :: n1
        integer, pointer :: a(:) => null()
      end type n1
      type :: n0
        integer, pointer :: a(:) => null()
        type(n1), allocatable :: nx(:)
      end type n0
      type(n0) :: r
      integer :: q, hf, tot
      logical :: ok
      hf = 1
      !$omp target map(from: hf)
      hf = merge(1, 0, omp_is_initial_device())
      !$omp end target
      allocate(r%nx(2))
      allocate(r%a(4))
      allocate(r%nx(1)%a(4))
      allocate(r%nx(2)%a(4))
      r%a = 1
      r%nx(1)%a = 2
      r%nx(2)%a = 3
      !$omp target enter data map(to: r)
      !$omp target enter data map(to: r%nx(1)%a) map(to: r%nx(2)%a)
      !$omp target map(tofrom: tot)
        tot = sum(r%nx(1)%a) + sum(r%nx(2)%a)
      !$omp end target
      !$omp target exit data map(release: r%nx(1)%a) map(release: r%nx(2)%a)
      !$omp target exit data map(release: r)
      ok = tot == 20
      print '(a,i0)', 'tot= ', tot
      print '(a,i0,a,a)', 'RESULT ran_on_host=', hf, ' check=', merge('pass', 'fail', ok)
    end program t
    
  • one change from the finding; correct on gcc_g90, gcc_sm80: not run yet
    Control program
    ! control: the root pointer only (elements not read)
    program t
      use omp_lib
      implicit none
      type :: n1
        integer, pointer :: a(:) => null()
      end type n1
      type :: n0
        integer, pointer :: a(:) => null()
        type(n1), allocatable :: nx(:)
      end type n0
      type(n0) :: r
      integer :: q, hf, tot
      logical :: ok
      hf = 1
      !$omp target map(from: hf)
      hf = merge(1, 0, omp_is_initial_device())
      !$omp end target
      allocate(r%nx(2))
      allocate(r%a(4))
      allocate(r%nx(1)%a(4))
      allocate(r%nx(2)%a(4))
      r%a = 1
      r%nx(1)%a = 2
      r%nx(2)%a = 3
      !$omp target enter data map(to: r)
      !$omp target enter data map(to: r%a)
      !$omp target map(tofrom: tot)
        tot = sum(r%a)
      !$omp end target
      !$omp target exit data map(release: r%a)
      !$omp target exit data map(release: r)
      ok = tot == 4
      print '(a,i0)', 'tot= ', tot
      print '(a,i0,a,a)', 'RESULT ran_on_host=', hf, ' check=', merge('pass', 'fail', ok)
    end program t
    

Other compilers run it correctly

AFAR 24.3.0, CCE 19.0.0, CCE 20.0.2, CCE 21.0.3, CCE 21.0.4, NVHPC 25.11, NVHPC 26.9