]> git.ipfire.org Git - thirdparty/gcc.git/commit
C prototypes for external arguments; add warning for mismatch.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 4 Mar 2025 19:13:19 +0000 (20:13 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 4 Mar 2025 19:16:06 +0000 (20:16 +0100)
commit21ca9153ebe525b077ac96811cfd48be6b259e7e
treeaae3128ff1e661f1868938e09010359bc124040e
parent9ee39fcb15bd6ebd636ee65599b34a4c0d0818e4
C prototypes for external arguments; add warning for mismatch.

The problem was that we were not handling external dummy arguments
with -fc-prototypes-external. In looking at this, I found that we
were not warning about external procedures with different argument
lists.  This can actually be legal (see the two test cases) but
creates a problem for the C prototypes: If we have something like

subroutine foo(a,n)
  external a
  if (n == 1) call a(1)
  if (n == 2) call a(2,3)
end subroutine foo

then, pre-C23, we could just have written out the prototype as

void foo_ (void (*a) (), int *n);

but this is illegal in C23. What to do?  I finally chose to warn
about the argument mismatch, with a new option. Warn only because the
code above is legal, but include in -Wall because such code seems highly
suspect.  This option is also implied in -fc-prototypes-external. I also
put a warning in the generated header file in that case, so users
have a chance to see what is going on (especially since gcc now
defaults to C23).

gcc/fortran/ChangeLog:

PR fortran/119049
PR fortran/119074
* dump-parse-tree.cc (seen_conflict): New static varaible.
(gfc_dump_external_c_prototypes): Initialize it. If it was
set, write out a warning that -std=c23 will not work.
(write_proc): Move the work of actually writing out the
formal arglist to...
(write_formal_arglist): New function. Handle external dummy
parameters and their argument lists. If there were mismatched
arguments, output an empty argument list in pre-C23 style.
* gfortran.h (struct gfc_symbol): Add ext_dummy_arglist_mismatch
flag and formal_at.
* invoke.texi: Document -Wexternal-argument-mismatch.
* lang.opt: Put it in.
* resolve.cc (resolve_function): If warning about external
argument mismatches, build a formal from actual arglist the
first time around, and later compare and warn.
(resolve_call): Likewise

gcc/testsuite/ChangeLog:

PR fortran/119049
PR fortran/119074
* gfortran.dg/interface_55.f90: New test.
* gfortran.dg/interface_56.f90: New test.
gcc/fortran/dump-parse-tree.cc
gcc/fortran/gfortran.h
gcc/fortran/invoke.texi
gcc/fortran/lang.opt
gcc/fortran/resolve.cc
gcc/testsuite/gfortran.dg/interface_55.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/interface_56.f90 [new file with mode: 0644]