public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9118] Fortran: error handling of global entity appearing in COMMON block [PR103259]
@ 2023-02-09 20:13 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-02-09 20:13 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2b3352b5d65bdb3fd612bbe0abe336226987d602
commit r12-9118-g2b3352b5d65bdb3fd612bbe0abe336226987d602
Author: Steve Kargl <kargl@gcc.gnu.org>
Date: Tue Feb 7 20:18:42 2023 +0100
Fortran: error handling of global entity appearing in COMMON block [PR103259]
gcc/fortran/ChangeLog:
PR fortran/103259
* resolve.cc (resolve_common_vars): Avoid NULL pointer dereference
when a symbol's location is not set.
gcc/testsuite/ChangeLog:
PR fortran/103259
* gfortran.dg/pr103259.f90: New test.
(cherry picked from commit 7e9f20f5517429cfaadec14d6b04705e59078565)
Diff:
---
gcc/fortran/resolve.cc | 12 +++++++++---
gcc/testsuite/gfortran.dg/pr103259.f90 | 11 +++++++++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index a1a91dc425f..565b212c4c8 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -953,9 +953,15 @@ resolve_common_vars (gfc_common_head *common_block, bool named_common)
{
gsym = gfc_find_gsymbol (gfc_gsym_root, csym->name);
if (gsym && (gsym->type == GSYM_MODULE || gsym->type == GSYM_PROGRAM))
- gfc_error_now ("Global entity %qs at %L cannot appear in a "
- "COMMON block at %L", gsym->name,
- &gsym->where, &csym->common_block->where);
+ {
+ if (csym->common_block)
+ gfc_error_now ("Global entity %qs at %L cannot appear in a "
+ "COMMON block at %L", gsym->name,
+ &gsym->where, &csym->common_block->where);
+ else
+ gfc_error_now ("Global entity %qs at %L cannot appear in a "
+ "COMMON block", gsym->name, &gsym->where);
+ }
/* gfc_add_in_common may have been called before, but the reported errors
have been ignored to continue parsing.
diff --git a/gcc/testsuite/gfortran.dg/pr103259.f90 b/gcc/testsuite/gfortran.dg/pr103259.f90
new file mode 100644
index 00000000000..f78ff26180e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103259.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/103259 - ICE in resolve_common_vars
+! Contributed by G.Steinmetz
+
+module m
+ integer :: p
+ common /c/ p
+end
+program p ! { dg-error "cannot appear in a COMMON block" }
+ use m ! { dg-error "is also the name of the current program unit" }
+end
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-09 20:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 20:13 [gcc r12-9118] Fortran: error handling of global entity appearing in COMMON block [PR103259] Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).