See PR for some analysis. The problem is that during
gfc_intrinsic_func_interface, sym->attr.flavor == FL_PROCEDURE,
hence, attr.intrinsic is not set – but later when parsing
'null()', gfortran calls:
if (sym->attr.proc != PROC_INTRINSIC
&& !(sym->attr.use_assoc && sym->attr.intrinsic)
&& (!gfc_add_procedure(&sym->attr, PROC_INTRINSIC, sym->name, NULL)
|| !gfc_add_function (&sym->attr, sym->name, NULL)))
return MATCH_ERROR;
The gfc_add_procedure call fails as 'sym' is use-associated and
may not be modified.
The obvious solution to also set attr.intrinsic for FL_PROCEDURE fails
in multiple ways, e.g. for gfortran.dg/char_length_16.f90 which has:
CHARACTER (LEN(ITEMVAL)) :: ITEM
INTRINSIC LEN
the error is that INTRINSIC has been speicified twice. It also affects
the error diagnostic in for generic resolution due to (I think):
if (sym->attr.intrinsic)
return gfc_intrinsic_func_interface (expr, 0);
For gfortran.dg/allocatable_scalar_11.f90 the specific
‘array’ argument of ‘allocated’ intrinsic at (1) must be a variable
gets replaced by the generic
Generic function 'allocated' at (1) is not consistent with a specific
intrinsic interface
I have now tried it as shown. I think attr.function was not set, but
am not sure. But setting it again for FL_PROCEDURE looks sensible.
I am far from certain that now everything fits together, but I do hope
that nothing fails which did work before ...
OK for mainline? And after waiting a while for GCC 10?
Tobias
PS: I did see once a fail for pr93792.f90 (additional error as 't' in type(t)
is not known) – but I could not reproduce it; the error is valid but later runs
stopped with 'cannot open module file' and did not reach that follow-up error.
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank
Thürauf
Fortran: Fix intrinsic null() handling [PR99651]
gcc/fortran/ChangeLog:
PR fortran/99651
* intrinsic.c (gfc_intrinsic_func_interface): Set
attr.proc = PROC_INTRINSIC if FL_PROCEDURE.
gcc/testsuite/ChangeLog:
PR fortran/99651
* gfortran.dg/null_11.f90: New test.
gcc/fortran/intrinsic.c | 5 +++++
gcc/testsuite/gfortran.dg/null_11.f90 | 16 ++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index e68eff8bdbb..17fd92eb462 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -5071,6 +5071,11 @@ got_specific:
sym->attr.intrinsic = 1;
sym->attr.flavor = FL_PROCEDURE;
}
+ if (sym->attr.flavor == FL_PROCEDURE)
+ {
+ sym->attr.function = 1;
+ sym->attr.proc = PROC_INTRINSIC;
+ }
if (!sym->module)
gfc_intrinsic_symbol (sym);
diff --git a/gcc/testsuite/gfortran.dg/null_11.f90 b/gcc/testsuite/gfortran.dg/null_11.f90
new file mode 100644
index 00000000000..040cc260b5d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/null_11.f90
@@ -0,0 +1,16 @@
+! { dg-do compile }
+!
+! PR fortran/99651
+!
+module m
+ type :: CHAR_STAR
+ character(len=1),dimension(:),pointer :: ptr
+ end type
+ type(CHAR_STAR), parameter ::CHAR_STAR_NULL = CHAR_STAR(NULL())
+end module m
+
+use m
+type typeNode
+ type(typeNode), pointer :: Next => null()
+end type typeNode
+end