All, Paul,
In testing Paul's recent addition of support for IMPORT,
I have uncovered an ICE due to mangled source code. The
code leads to a NULL pointer dereference. The patch that
follows my .sig fixes the issue. Note the testcase has one
FAIL.
% gmake check-fortran RUNTESTFLAGS="dg.exp=import13.f90"
...
Running /home/kargl/gcc/gcc/gcc/testsuite/gfortran.dg/dg.exp ...
FAIL: gfortran.dg/import13.f90 -O (test for excess errors)
=== gfortran Summary ===
# of expected passes 4
# of unexpected failures 1
/home/kargl/gcc/obj/gcc/gfortran version 16.0.0 20250712 (experimental) (GCC)
% gfcx -c a.f90
a.f90:13:20:
9 | subroutine bah ! { dg-error "is already defined at" }
| 2~~~~~~~~~~~~~
......
13 | subroutine bah
| 1
Error: Procedure 'bah' at (1) is already defined at (2)
a.f90:15:71:
I do not remember how to deal with multi-line error messages
in the dg-error case. Any guidance?
--
Steve
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 111ebc5f845..af425754d08 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -5272,13 +5272,15 @@ gfc_match_import (void)
switch (m)
{
case MATCH_YES:
- if (gfc_current_ns->parent != NULL
+ if (gfc_current_ns->parent != NULL
&& gfc_find_symbol (name, gfc_current_ns->parent, 1, &sym))
{
gfc_error ("Type name %qs at %C is ambiguous", name);
return MATCH_ERROR;
}
- else if (!sym && gfc_current_ns->proc_name->ns->parent != NULL
+ else if (!sym
+ && gfc_current_ns->proc_name
+ && gfc_current_ns->proc_name->ns->parent
&& gfc_find_symbol (name,
gfc_current_ns->proc_name->ns->parent,
1, &sym))
@@ -5289,7 +5291,8 @@ gfc_match_import (void)
if (sym == NULL)
{
- if (gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY)
+ if (gfc_current_ns->proc_name
+ && gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY)
{
gfc_error ("Cannot IMPORT %qs from host scoping unit "
"at %C - does not exist.", name);
diff --git a/gcc/testsuite/gfortran.dg/import13.f90
b/gcc/testsuite/gfortran.dg/import13.f90
new file mode 100644
index 00000000000..2e4470aada2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/import13.f90
@@ -0,0 +1,18 @@
+! { dg-do compile }
+program foo
+ implicit none
+ integer i
+ i = 42
+ if (i /= 42) stop 1
+ call bah
+ contains
+ subroutine bah ! { dg-error "is already defined at" }
+ i = 43
+ if (i /= 43) stop 2
+ end subroutine bah
+ subroutine bah
+ ! import statement missing a comma
+ import none ! { dg-error "Unexpected IMPORT statement" }
+ i = 44 ! { dg-error "Unexpected assignment" }
+ end subroutine bah ! { dg-error "Expecting END PROGRAM" }
+end program foo