Hi PA,

Paul-Antoine Arras wrote:
See the revised patch attached and my comments below.

First, for Fortran patches, please also CC fortran@ besides gcc-patches@.

The original patch email can be found at:
https://gcc.gnu.org/pipermail/gcc-patches/2024-December/671763.html

I have not looked in depth at the patch, but managed to
write C-ism code, which caused a segfault (due to a missing "call"),
after gfortran issued a reasonable error. Can you fix it
and, just to make sure, add it as another testcase?

foo.f90:18:7:

   18 |      g(a,b,c)
      |       1
Error: ‘g’ at (1) is not a variable
foo.f90:20:3:

   20 | end
      |   1
Error: Unexpected END statement at (1)

Segmentation fault

* * *

The problem seems to be that during parsing,
the location data is NULL, which the error diagnostic does not like: (gdb) p gfc_current_locus $33 = {nextc = 0x0, u = {lb = 0x0, location = 0}} (gdb) p gfc_at_eof() $36 = true and st == ST_NONE. I think the simplest is to check for the last one, and then return early. This will then print: foo.f90:18:7: 18 | g(a,b,c) | 1 Error: ‘g’ at (1) is not a variable foo.f90:20:3: 20 | end | 1 Error: Unexpected END statement at (1) f951: Error: Unexpected end of file in ‘foo.f90’ When the if st is ST_NONE then return check is added: +static gfc_statement +parse_omp_dispatch (void) +{ ... + st = next_statement (); + if (st == ST_NONE) + return st; + if (st == ST_CALL || st == ST_ASSIGNMENT) + accept_statement (st); + else * * * > Handling of `adjust_args` across translation units is missing due to PR115271. Namely, https://gcc.gnu.org/PR115271 is about not storing 'declare variant' inside module files; when repeating the decl in an interface, it obviously works as * * * I think the patch is now okay, but I want to re-read it tomorrow - thus, please hold off for a couple of ours. Possibly, others have comments as well :-) * * *

TODO: We need to handle 'type(C), dimension(:)' - but I wonder
whether that shouldn't be handled as part of 'use_device_addr'
and we need to check whether the spec has to be updated.

I filed the OpenMP lang-spec Issue #4443.
... and we eventually have to handle 'need_device_addr'/'has_device_addr', but those are follow-up topics.

Thanks,

Tobias
module m
use iso_c_binding
implicit none(type,external)
contains
subroutine f(x,y,z)
  type(c_ptr) :: x,y,z
end
subroutine g(x,y,z)
  type(c_ptr) :: x,y,z
  !$omp declare variant(f) adjust_args(need_device_ptr: x,y) adjust_args(nothing : z,x) match(construct={dispatch})
end
end 

use m
implicit none(type,external)
  type(c_ptr) :: a,b,c
  !$omp dispatch
     g(a,b,c)
!    call g(a,b,c)
end

Reply via email to