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);

Reply via email to