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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
@Patrick: It seems to work fine without "finalize".

Can you check whether the big program then works for you?
Usually, one should be able to do proper ref counting such that a
 'finalize' -> force setting refcounts to zero
shouldn't be needed.

* * *

Looking at the code more closely, the problem is:

  #pragma omp target oacc_exit_data map(delete:tab.val.data [len: 88])

this tries to 'delete' the array descriptor - but as tab.val.data is part of
'tab', this deletes all of "tab".


Compare the C example:

struct t { int *a; int n; };
void f() {
  struct t s;
  #pragma acc enter data copyin(s.a[:s.n])
  #pragma acc exit data delete(s.a[:s.n])
  // for completeness, not relevant here:
  #pragma acc exit data detach(s.a)
  #pragma acc exit data delete(s.a)
}


GCC does:

 #pragma omp target oacc_enter_data map(struct:s [len: 1]) \
     map(alloc:s.a [len: 8]) map(to:*_4 [len: _3]) map(attach:s.a [bias: 0])

 #pragma omp target oacc_exit_data map(release:s.a [len: 8]) \
     map(release:*_8 [len: _7]) map(detach:s.a [bias: 0])

 #pragma omp target oacc_exit_data map(detach:s.a [bias: 0])
 #pragma omp target oacc_exit_data map(release:s.a [len: 8])

which seems to be at least consistent. Again, here a 'finalize' would force the
reference counts to zero and, hence, also delete 's' and not only the
pointee/pointer target *s.a / s.a[0:.n] but also the pointer 's.a' itself.

(BTW: Same result since GCC 10; GCC 9 rejects that code.)

 * * *

QUESTION: Is the current code for C (and Fortran) correct according to the
OpenACC specification or not?

FOLLOW UP QUESTION: If GCC's result is incorrect, what should the compiler do
instead?
And if it is correct, the question is: why do both ftn and nvfortran work in
the same way?

Reply via email to