https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121975

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Looking at the extra output, one can find e.g. for
kernels-decompose-pr104774-1.c the following additional output:

c-c++-common/goacc/kernels-decompose-pr104774-1.c:22:9: note: beginning
‘gang-single’ part in OpenACC ‘kernels’ region


That's for the code:

#pragma acc kernels
  {
    int k;  // Line 22 → k = .DEFERRED_INIT (4, 2, &"k"[0]);

    #pragma acc loop seq /* { dg-line l_loop_k1 } */
    for (k = 0; k < 2; k++)


Which is turned into:

#pragma omp target oacc_data_kernels map(force_tofrom:arr_0 [len: 4])
...
  #pragma omp target oacc_data_kernels map(alloc:k [len: 4])
...
// This code exists only with DEFERRED_INIT (in omplower):
     #pragma omp target oacc_parallel_kernels_gang_single async(-1)
num_gangs(1) \
                 map(force_present:k [len: 4]) map(force_present:arr_0 [len:
4]) \
                 [...]
         D.2849 = .omp_data_i->k;
         D.2850 = .DEFERRED_INIT (4, 2, &"k"[0]);
         *D.2849 = D.2850;
         #pragma omp return

// This is the normal code for the loop, which exits for both:
    #pragma omp target oacc_parallel_kernels_parallelized async(-1) \
                map(force_present:k [len: 4]) map(force_present:arr_0 [len: 4])
\
                [...]


Thus, this extra diagnostic makes sense. For "k = 0;" the generated code looks
identical - except that '= 0' and not '= .DEFERRED_INIT (...)' appears in the
dump.

I wonder whether there is something smarter than adding this extra code, which
makes things slow, but is at the end pointless because at the end, 'k' only
appears as:

  #pragma acc loop private(k) seq
    for (k = 0; k < 2; k = k + 1)

such that 'k' is not really been used uninitialized – it is just propagated
through (i.e. mapped) uninitialized - but the actual use is a privatized
variable.

* * *

Thus, at least this part looks consistent - and doing the following would be
fine:

--- a/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr104774-1.c
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr104774-1.c
@@ -21,2 +21,4 @@ foo (void)
   {
+    /* Cf. PR121975; due to C++26's '-ftrivial-auto-var-init=zero': */
+    /* { dg-message {beginning} {beginning 'gang-single' part in OpenACC
'kernels' region} { target c++26 } .+1 } */
     int k;

Reply via email to