public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/111218] Conflict in BIND(C) INTERFACEs in two Modules leads to ICE.
Date: Sat, 14 Oct 2023 02:00:02 +0000	[thread overview]
Message-ID: <bug-111218-4-aa08tqzYiv@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111218-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111218

--- Comment #5 from kargl at gcc dot gnu.org ---
Interesting bug.  If one puts a break point ...

0x75917d gfc_format_decoder
        /home/toon/compilers/gcc/gcc/fortran/error.cc:1078
0x2153e1f pp_format(pretty_printer*, text_info*)
        /home/toon/compilers/gcc/gcc/pretty-print.cc:1475
0x21315be diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
        /home/toon/compilers/gcc/gcc/diagnostic.cc:1606
0x9b628e gfc_report_diagnostic
        /home/toon/compilers/gcc/gcc/fortran/error.cc:890
0x9b628e gfc_error_opt
        /home/toon/compilers/gcc/gcc/fortran/error.cc:1460
0x9b7470 gfc_error(char const*, ...)
        /home/toon/compilers/gcc/gcc/fortran/error.cc:1489
0xa6205b ambiguous_symbol
        /home/toon/compilers/gcc/gcc/fortran/symbol.cc:3167

here, one ends up at 

        gfc_error ("Name %qs at %C is an ambiguous reference to %qs from"
                   "module %qs", name, st->n.sym->name, st->n.sym->module);

%C means one should use gfc_current_locus to print the offending line.
If one looks are gfc_current_locus, one sees gfc_current_locus.lb = 0x0,
an infamous NULL pointer dereference then occurs.  Ouch.  This patch 
fixes the issue:

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index a6078bc608a..5b726f8b715 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -3164,8 +3164,16 @@ ambiguous_symbol (const char *name, gfc_symtree *st)
     return;

   if (st->n.sym->module)
-    gfc_error ("Name %qs at %C is an ambiguous reference to %qs "
-              "from module %qs", name, st->n.sym->name, st->n.sym->module);
+    {
+      if (gfc_current_locus.lb)
+       gfc_error ("Name %qs at %C is an ambiguous reference to %qs from"
+                  "module %qs", name, st->n.sym->name, st->n.sym->module);
+      else
+       gfc_error ("Name %qs is an ambiguous reference to %qs, which is "
+                  "available through USE association from module %qs at %L",
+                  name, st->n.sym->name, st->n.sym->module,
+                  &st->n.sym->declared_at);
+    }
   else
     gfc_error ("Name %qs at %C is an ambiguous reference to %qs "
               "from current program unit", name, st->n.sym->name);

  parent reply	other threads:[~2023-10-14  2:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-28 19:28 [Bug fortran/111218] New: " toon at moene dot org
2023-08-28 23:14 ` [Bug fortran/111218] " kargl at gcc dot gnu.org
2023-08-29 16:47 ` anlauf at gcc dot gnu.org
2023-08-29 16:51 ` anlauf at gcc dot gnu.org
2023-08-31 10:41 ` rimvydas.jas at gmail dot com
2023-10-14  2:00 ` kargl at gcc dot gnu.org [this message]
2023-10-14  2:08 ` kargl at gcc dot gnu.org
2023-10-14  2:30 ` kargl at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-111218-4-aa08tqzYiv@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).