Done.
commit 2c1fd2fdb3029fdd3ea3f88fe635f37b3a5fae36 (HEAD -> master, origin/master,
origin/HEAD)
Author: Steven G. Kargl <ka...@gcc.gnu.org>
Date: Thu Aug 21 14:31:16 2025 -0700
Fortran: Fix NULL pointer issue.
PR fortran/121627
gcc/fortran/ChangeLog:
* module.cc (create_int_parameter_array): Avoid NULL
pointer dereference and enhance error message.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr121627.f90: New test.
On 8/21/25 1:42 PM, Jerry D wrote:
On 8/21/25 12:32 PM, Steve Kargl wrote:
fortran/121627 found an issue with a NULL pointer dereference
when the name of the main program conflicts with a symbol in
iso_fortran_env. The following patch fixes the issue. While
here I've expanded the error message to hopefully explain the
issue.
2025-08-21 Steven G. Kargl <ka...@gcc.gnu.org>
PR fortran/121627
* gcc/fortran/module.cc (create_int_parameter_array): Avoid NULL
pointer dereference and enhance error message.
* gcc/testsuite/gfortran.dg/pr121627.f90: New test
The patch survived regression testing on x86_64-*-*freebsd.
Hello Steve,
This looks reasonable to me and OK for trunk. I will commit for you after I
apply and test on Linux x86_64. (Unless you want to commit yourself)
(I will make sure I git you as author. I forget to do that sometimes.)
Thanks,
Jerry
diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc
index 070b3164ea3..e05b08bd14e 100644
--- a/gcc/fortran/module.cc
+++ b/gcc/fortran/module.cc
@@ -7277,10 +7277,13 @@ create_int_parameter_array (const char *name, int
size, gfc_expr *value,
tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
if (tmp_symtree != NULL)
{
- if (strcmp (modname, tmp_symtree->n.sym->module) == 0)
+ if (tmp_symtree->n.sym->module &&
+ strcmp (modname, tmp_symtree->n.sym->module) == 0)
return;
else
- gfc_error ("Symbol %qs already declared", name);
+ gfc_error ("Symbol %qs already declared at %L conflicts with "
+ "symbol in %qs at %C", name,
+ &tmp_symtree->n.sym->declared_at, modname);
}
gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
diff --git a/gcc/testsuite/gfortran.dg/pr121627.f90 b/gcc/testsuite/
gfortran.dg/pr121627.f90
new file mode 100644
index 00000000000..c3ce218880c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr121627.f90
@@ -0,0 +1,5 @@
+! { dg-do compile }
+program real_kinds ! { dg-error "already declared at" }
+ use iso_fortran_env ! { dg-error "already declared at" }
+ i = real64
+end program real_kinds