OffTarget

Observed issues › catalog/cce-acc-character-dummy-routine-ice

Appears to behave incorrectlyCompiler crash · Fortran · OpenACC · Open

ftn -h acc: internal compiler error "Bad cast from fcd" for a CHARACTER(len=*) dummy of a routine seq procedure

Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked

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.0n/an/an/an/an/an/an/a
CCE 19.0.0fails another wayfails another wayfails another wayunknown
not run
unknown
not run
n/an/a
CCE 20.0.2behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 21.0.3behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 21.0.4behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/afails another wayfails another way
NVHPC 26.9n/an/an/an/an/afails another wayfails another way
GCC 16.2.0correctcorrectcorrectcorrectcorrectcorrectn/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 incorrectlyCCE 20.0.2, MI300A unified
CCE 20.0.2, MI300A copy
CCE 20.0.2, MI250X
show
Warning:
 Headers and libraries from cray-libsci/25.09.0 will be ignored because depends on PE_MPICH which is unavailable..
   Error message      ::  Bad cast from fcd to ... 
   Error detected     ::  File '/workspace/crayftn/pdgcs/llvm-uex-expr.c', line 620
   Optimizer built    ::  2025-11-17 (production)
   File               ::  cce-acc-character-dummy-routine-ice.f90
   Function           ::  wide_prog_
   at or near line    ::  29
behaves incorrectlyCCE 21.0.3, MI300A unified
CCE 21.0.3, MI300A copy
CCE 21.0.3, MI250X
show
Warning:
 Headers and libraries from cray-libsci/26.03.0 will be ignored because depends on PE_MPICH which is unavailable..
   Error message      ::  Bad cast from fcd to ... 
   Error detected     ::  File '/workspace/crayftn/pdgcs/llvm-uex-expr.c', line 620
   Optimizer built    ::  2026-07-14 (production)
   File               ::  cce-acc-character-dummy-routine-ice.f90
   Function           ::  wide_prog_
   at or near line    ::  29
behaves incorrectlyCCE 21.0.4, MI300A unified
CCE 21.0.4, MI300A copy
CCE 21.0.4, MI250X
show
Warning:
 Headers and libraries from cray-libsci/26.03.0 will be ignored because depends on PE_MPICH which is unavailable..
   Error message      ::  Bad cast from fcd to ... 
   Error detected     ::  File '/workspace/crayftn/pdgcs/llvm-uex-expr.c', line 620
   Optimizer built    ::  2026-09-24 (production)
   File               ::  cce-acc-character-dummy-routine-ice.f90
   Function           ::  wide_prog_
   at or near line    ::  29
fails another wayCCE 19.0.0, MI300A unified
CCE 19.0.0, MI300A copy
CCE 19.0.0, MI250X
show
Warning:
 Headers and libraries from cray-libsci/25.03.0 will be ignored because depends on PE_MPICH which is unavailable..
  integer function code(c)
ftn-7066 ftn: ERROR CODE, File = cce-acc-character-dummy-routine-ice.f90, Line = 4 
  Unsupported accelerator code error: Fortran character
ftn-7066 ftn: ERROR CODE, File = cce-acc-character-dummy-routine-ice.f90, Line = 4 
  Unsupported accelerator code error: Fortran character -- c
    b(i) = code(s(1:mod(i, 8) + 1))
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
show
NVFORTRAN-S-0155-Compiler failed to translate accelerator region (see -Minfo messages): Character local variable unsupported on device (cce-acc-character-dummy-routine-ice.f90: 26)
NVFORTRAN-F-0704-Compilation aborted due to previous errors. (cce-acc-character-dummy-routine-ice.f90)
NVFORTRAN/x86-64 Linux 25.11-0: compilation aborted
fails another wayNVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
NVFORTRAN-S-0155-Compiler failed to translate accelerator region (see -Minfo messages): Character local variable unsupported on device (cce-acc-character-dummy-routine-ice.f90: 26)
NVFORTRAN-F-0704-Compilation aborted due to previous errors. (cce-acc-character-dummy-routine-ice.f90)
NVFORTRAN/x86-64 Linux 26.9-0: compilation aborted

Reproduce

CCE 20.0.2, MI300A unified

module load cce/20.0.2 craype-accel-amd-gfx942 rocm/6.4.3
module unload cray-mpich
ftn -h acc -O2 repro.f90 -o repro
HSA_XNACK=1 ./repro

CCE 21.0.3, MI300A unified

module load cce/21.0.3 craype-accel-amd-gfx942 rocm/7.2.0
module unload cray-mpich
ftn -h acc -O2 repro.f90 -o repro
HSA_XNACK=1 ./repro

CCE 21.0.4, MI300A unified

module load cce/21.0.4 craype-accel-amd-gfx942 rocm/7.2.0
module unload cray-mpich
ftn -h acc -O2 repro.f90 -o repro
HSA_XNACK=1 ./repro

GCC 16.2.0, MI300A unified (runs correctly)

export LD_LIBRARY_PATH=$GCC_16_2/lib64:/opt/rocm-7.2.1/lib
$GCC_16_2/bin/gfortran -fopenacc -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.f90 -o repro
HSA_XNACK=1 ./repro
Program (74 lines)
! # Draft finding: acc34-w-routine-character on cce20
!
! - compiler: cce20
! - toolchain: cce20; arch: gfx942; machine: tuolumne; memory mode: unified; opt: -O2
! - program: catalog acc34-w-routine-character (f90, version 34, sha256 976490e860a6112c)
! - expected: None (None; )
! - actual: ice  (ice: INTERNAL COMPILER ERROR:  "Bad cast from fcd to ... " (/workspace/crayftn/pdgcs/llvm-uex-expr.c, line 620,
!   version 668d73f9607c0349bd23641a3a25a1acfac374de))
! - verdict: compiler_bug by rule R10-compile-ice: an internal compiler error (or the compiler rejecting code it generated) on a
!   legal program: always the compiler's defect
! - reason: 
! - citations: RUL-COMPILE-TIME (rulings.md)
! - legality: legal: offload.engine.prerun.check accepts it (rerun: offload.engine.rules with the
!   race rule and the restriction checks, and the AFAR flang front end, not under test here); no
!   compiler under test, gfortran or gcc is a legality witness
! - witnesses: none
! - withdrawn: none
!
! Generated by compliance.widen (OpenACC 3.4, free-form Fortran; catalog widening). Do not edit.
! id: acc34-w-routine-character
! primary atom: pair.base.device.routine_call+base.device.character
! atoms: pair.base.device.routine_call+base.device.character, base.device.routine_call, base.device.character
! legal: yes
! observable: yes
! ran_on_host: inside the compute region of interest (acc_on_device)
! evidence: construct
! needs: none
! std: f2008
! feature: a device routine with a CHARACTER(len=*) dummy
! spec: the parts' own programs
! pair of: base.device.routine_call + base.device.character (each has a program of its own)
module wmod
  implicit none
contains
  integer function code(c)
    !$acc routine seq
    character(len=*), intent(in) :: c
    code = ichar(c(1:1)) + len(c)
  end function code
end module wmod

program wide_prog
  use openacc, only: acc_device_host, acc_on_device
  use wmod
  implicit none
  integer, parameter :: n = 64
  integer :: a(n), b(n), ref(n)
  character(len=8) :: s
  integer :: i, host_flag
  logical :: ok
  do i = 1, n
    a(i) = i
    b(i) = 0
    ref(i) = 97 + mod(i, 8) + 1
  end do
  host_flag = 1
  !$acc parallel loop copyin(a) copyout(b) copy(host_flag) private(s)
  do i = 1, n
    s = 'abcdefgh'
    b(i) = code(s(1:mod(i, 8) + 1))
    if (i == 1) host_flag = merge(1, 0, acc_on_device(acc_device_host))
  end do
  ok = all(b == ref)
  print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
end program wide_prog
! spec (requirement): The routine directive tells the compiler to compile a procedure for the accelerator as well as
!   the host.
! "The routine directive is used to tell the compiler to compile the definition for a procedure, such as a function or
!   C++ lambda, for an accelerator as well as for the host." (OpenACC 3.4 §2.15.1 p.91 l.3321-3323)
! spec (requirement): A call to a seq routine may appear in any mode, including from a loop in a parallel region.
! "A call to this procedure may appear in any mode." (OpenACC 3.4 §2.15.1 p.93 l.3404)
! spec (this program): The seq routine code takes a character(len=*) dummy; the spec places no restriction on the
!   argument types of a routine procedure (the glossary treats character variables as aggregate variables), so the
!   call with a substring is legal, and ftn stops with an internal error (Bad cast from fcd).

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

Warning:
 Headers and libraries from cray-libsci/25.09.0 will be ignored because depends on PE_MPICH which is unavailable..
   Error message      ::  Bad cast from fcd to ... 
   Error detected     ::  File '/workspace/crayftn/pdgcs/llvm-uex-expr.c', line 620
   Optimizer built    ::  2025-11-17 (production)
   File               ::  cce-acc-character-dummy-routine-ice.f90
   Function           ::  wide_prog_
   at or near line    ::  29

What the specification requires

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

OpenACC 3.4 §2.15.1 p.91 l.3321-3323

The routine directive is used to tell the compiler to compile the definition for a procedure, such as a function or C++ lambda, for an accelerator as well as for the host.

OpenACC 3.4 §2.15.1 p.93 l.3404

A call to this procedure may appear in any mode.

Evidence

Same compiler, one change

  • the routine takes the character's code and length as integers instead of the CHARACTER(len=*) dummy: CCE 19.0.0: correct; CCE 20.0.2: correct; CCE 21.0.3: correct; CCE 21.0.4: correct
    Control program
    module wmod
      implicit none
    contains
      integer function code(k, l)
        !$acc routine seq
        integer, intent(in) :: k, l
        code = k + l
      end function code
    end module wmod
    
    program wide_prog
      use openacc, only: acc_device_host, acc_on_device
      use wmod
      implicit none
      integer, parameter :: n = 64
      integer :: a(n), b(n), ref(n)
      character(len=8) :: s
      integer :: i, host_flag
      logical :: ok
      do i = 1, n
        a(i) = i
        b(i) = 0
        ref(i) = 97 + mod(i, 8) + 1
      end do
      host_flag = 1
      !$acc parallel loop copyin(a) copyout(b) copy(host_flag) private(s)
      do i = 1, n
        s = 'abcdefgh'
        b(i) = code(ichar(s(1:1)), mod(i, 8) + 1)
        if (i == 1) host_flag = merge(1, 0, acc_on_device(acc_device_host))
      end do
      ok = all(b == ref)
      print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
    end program wide_prog
    

Other compilers run it correctly

GCC 16.2.0