OffTarget

Observed issues › harvest/gcc-c-same-item-two-maps-rejected

Appears not to supportRefused at compile time · C · OpenMP · Open

The same variable in two map clauses of one target construct is rejected

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

OpenMP 5.2 allows a list item in more than one map clause of one directive. GCC 16.2 rejects a target construct with map(alloc: x) map(tofrom: x) for both offload targets; its documentation does not list the gap.

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/acorrectcorrect
NVHPC 26.9n/an/an/an/an/acorrectcorrect
GCC 16.2.0not supportednot supportednot supportednot supportednot supportednot supportedn/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
not supportedGCC 16.2.0, MI300A unified
GCC 16.2.0, MI300A copy
GCC 16.2.0, MI300X
GCC 16.2.0, MI350X
show
site-harvest--gcc-c-same-item-two-maps-rejected.c: In function ‘main’:
site-harvest--gcc-c-same-item-two-maps-rejected.c:31:31: error: ‘x’ appears more than once in map clauses
   31 | #pragma omp target map(alloc: x) map(tofrom: x) map(tofrom: host_flag)
      |                               ^
not supportedGCC 16.2.0, MI250X
GCC 16.2.0, A100 separate
show
site-harvest--gcc-c-same-item-two-maps-rejected.c: In function ‘main’:
site-harvest--gcc-c-same-item-two-maps-rejected.c:26:31: error: ‘x’ appears more than once in map clauses
   26 | #pragma omp target map(alloc: x) map(tofrom: x) map(tofrom: host_flag)
      |                               ^

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/gcc -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.c -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/gcc -fopenmp -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 repro.c -o repro
OMP_TARGET_OFFLOAD=mandatory ./repro

AFAR 24.3.0, MI300A unified (runs correctly)

$AFAR/bin/amdclang -fopenmp --offload-arch=gfx942 -O2 repro.c -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (39 lines)
// # Finding (GCC 16.2, harvests): the same variable in two map clauses of one target construct is rejected
//
// - toolchains: gcc_g90 (GCC 16.2.0, AMD Instinct MI250X gfx90a, Tioga) and gcc_sm80 (GCC 16.2.0, NVIDIA A100 sm_80, wingtip);
//   separate memory only; -O2
// - build: gcc -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx90a -O2 (gcc_g90); -foffload=nvptx-none
//   -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 (gcc_sm80)
// - failure: rejected: error: 'x' appears more than once in map clauses
// - observed: `error: 'x' appears more than once in map clauses` at the target directive, on both targets
// - expected: compiles; prints `x= 112` and `RESULT ran_on_host=0 check=pass`
// - rule: "A list item may appear more than once in the map clauses that are specified on the same directive" (5.2 §5.8.3 p.151
//   l.14-15).
// - same-compiler control (compiles; correct, gcc_sm80: mandatory pass 5 of 5; unset pass 5 of 5; gcc_g90: mandatory pass 5 of 5;
//   unset pass 5 of 5 (results/parity/<machine>/<tc>/probes.jsonl)): the variable in one map clause, map(tofrom: x)
//   (controls/gcc-c-same-item-two-maps-control.c).
// - GCC's documentation: no row of libgomp.texi's tables names it (undocumented). GCC's own development testsuite has programs of
//   this form (libgomp target-map-multi-*, harvested from gcc master 9e5dc385 into harvest2), so later GCC accepts it. On a target
//   data construct the same form ends in an internal compiler error instead (gcc-c-target-data-two-maps-ice.c).
// - other families: AFAR, CCE 19/20/21/21.0.4 and NVHPC 25.11/26.9 compile and run this file correctly (site matrix); on the
//   harvested programs AFAR and CCE are correct, NVHPC fails them another way. The site's finding matrix runs this file on every
//   compiler.
// - harvested programs (6 cells (3 gcc_g90, 3 gcc_sm80); gate: confirmed 6; confirmer: compiler_bug (R11-compile-rejection) 6):
//   h2-gomp-ccc-target-map-multi-1, h2-gomp-ccc-target-map-multi-2, hv-llvm-mapping-map-ordering-tgt-alloc-tofrom
// - legality: the pre-run check (offload.engine.prerun.check: the rules and AFAR's front end, two witnesses) accepts the harvested
//   programs. GCC is a compiler under test only and never a legality witness.
#include <stdio.h>
#include <omp.h>

int main(void) {
  int x = 111, host_flag = 1;
  /* the same list item in two map clauses of one construct */
#pragma omp target map(alloc: x) map(tofrom: x) map(tofrom: host_flag)
  {
    host_flag = omp_is_initial_device();
    x = x + 1;
  }
  printf("x= %d\n", x);
  printf("RESULT ran_on_host=%d check=%s\n", host_flag, x == 112 ? "pass" : "fail");
  return 0;
}

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

Expected

check=pass

Observed where it behaves incorrectly

site-harvest--gcc-c-same-item-two-maps-rejected.c: In function ‘main’:
site-harvest--gcc-c-same-item-two-maps-rejected.c:31:31: error: ‘x’ appears more than once in map clauses
   31 | #pragma omp target map(alloc: x) map(tofrom: x) map(tofrom: host_flag)
      |                               ^

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.14-15

A list item may appear more than once in the map clauses that are specified on the same directive

Evidence

Same compiler, one change

  • the variable in one map clause, map(tofrom: x): not run yet
    Control program
    // Control of harvest/gcc-c-same-item-two-maps-rejected.c: the variable in one map clause, map(tofrom: x) (compiles;
    // correct on gcc_g90 and gcc_sm80).
    #include <stdio.h>
    #include <omp.h>
    
    int main(void) {
      int x = 111, host_flag = 1;
      /* control: the list item in one map clause */
    #pragma omp target map(tofrom: x) map(tofrom: host_flag)
      {
        host_flag = omp_is_initial_device();
        x = x + 1;
      }
      printf("x= %d\n", x);
      printf("RESULT ran_on_host=%d check=%s\n", host_flag, x == 112 ? "pass" : "fail");
      return 0;
    }
    

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

Reproducers of this issue