]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Abstract interfaces and dummy arguments are not global.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 11 Mar 2025 16:40:57 +0000 (17:40 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 11 Mar 2025 16:42:38 +0000 (17:42 +0100)
The attached patch makes sure that procedures from abstract
interfaces and dummy arguments are not put into the global
symbol table, and are not checked against global symbols.

gcc/fortran/ChangeLog:

PR fortran/119078
* frontend-passes.cc (check_against_globals): Do not check
for abstract interfaces or dummy arguments.
* resolve.cc (gfc_verify_binding_labels): Adjust comment.
Do not put abstract interfaces or dummy argument into global
namespace.

gcc/testsuite/ChangeLog:

PR fortran/119078
* gfortran.dg/interface_58.f90: New test.

gcc/fortran/frontend-passes.cc
gcc/fortran/resolve.cc
gcc/testsuite/gfortran.dg/interface_58.f90 [new file with mode: 0644]

index 20bf6e127ffcb331c73cc69e9f082a112b28bf09..ef9c80147cc4fc0eda3290c9774fd79798918d6e 100644 (file)
@@ -5799,7 +5799,8 @@ check_against_globals (gfc_symbol *sym)
   char buf  [200];
 
   if (sym->attr.if_source != IFSRC_IFBODY || sym->attr.flavor != FL_PROCEDURE
-      || sym->attr.generic || sym->error)
+      || sym->attr.generic || sym->error || sym->attr.abstract
+      || sym->attr.dummy)
     return;
 
   if (sym->binding_label)
index eda31ba8adc388570545c9b7be6def868960ec38..027c99335d154e5778b62aa2039387c0cd12fd2f 100644 (file)
@@ -13883,7 +13883,8 @@ gfc_verify_DTIO_procedures (gfc_symbol *sym)
 
 /* Verify that any binding labels used in a given namespace do not collide
    with the names or binding labels of any global symbols.  Multiple INTERFACE
-   for the same procedure are permitted.  */
+   for the same procedure are permitted.  Abstract interfaces and dummy
+   arguments are not checked.  */
 
 static void
 gfc_verify_binding_labels (gfc_symbol *sym)
@@ -13892,7 +13893,8 @@ gfc_verify_binding_labels (gfc_symbol *sym)
   const char *module;
 
   if (!sym || !sym->attr.is_bind_c || sym->attr.is_iso_c
-      || sym->attr.flavor == FL_DERIVED || !sym->binding_label)
+      || sym->attr.flavor == FL_DERIVED || !sym->binding_label
+      || sym->attr.abstract || sym->attr.dummy)
     return;
 
   gsym = gfc_find_case_gsymbol (gfc_gsym_root, sym->binding_label);
diff --git a/gcc/testsuite/gfortran.dg/interface_58.f90 b/gcc/testsuite/gfortran.dg/interface_58.f90
new file mode 100644 (file)
index 0000000..52f3651
--- /dev/null
@@ -0,0 +1,38 @@
+! { dg-do compile }
+! PR 119078 - there should be no warning for dummy arguments
+! or abstract interfaces.
+module x
+  implicit none
+  abstract interface
+     subroutine foo() bind(c)
+     end subroutine foo
+  end interface
+  interface
+     subroutine baz() bind(c) ! { dg-warning "wrong number of arguments" }
+     end subroutine baz
+  end interface
+contains
+  subroutine tescht(bar) bind(c)
+    interface
+       subroutine bar() bind(c)
+       end subroutine bar
+    end interface
+  end subroutine tescht
+  subroutine t2(bar) bind(c)
+    procedure(foo) :: bar
+  end subroutine t2
+end module x
+
+subroutine foo(a)
+  real :: a
+end subroutine foo
+
+subroutine bar(b)
+  real :: b
+end subroutine bar
+
+subroutine baz(a) bind(c) ! { dg-warning "wrong number of arguments" }
+  use iso_c_binding, only : c_int
+  integer(c_int) :: a
+end subroutine baz
+