When the debugging switch -gnatdJ is present, warning messages include the
name of the unit within which the warning is generated. This patch fixes
a crash in the compiler when a warning appears within a child unit.

The command

  gcc -c -gnatdJ test-a.ads

must yield; 

test-a.ads:6:17: warning: Test.A: unused variable "X"

---
package Test is
end Test;
---
with Test;

package Test.A is

function P return Natural is (3) with
Pre => (for all X in Natural => True);

end Test.A;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  <schonb...@adacore.com>

        * sem_util.adb (Subprogram_Name): If this is a child unit, use the name
        of the Defining_Program_Unit_Name, which is an identifier, in order to
        construct the string for the fully qualified name.

Index: sem_util.adb
===================================================================
--- sem_util.adb        (revision 253559)
+++ sem_util.adb        (working copy)
@@ -23257,7 +23257,16 @@
          return "unknown subprogram";
       end if;
 
-      Append_Entity_Name (Buf, Ent);
+      if Nkind (Ent) = N_Defining_Program_Unit_Name then
+
+         --  If the subprogram is a child unit, use its simple name to
+         --  start the construction of the fully qualified name.
+
+         Append_Entity_Name (Buf, Defining_Identifier (Ent));
+
+      else
+         Append_Entity_Name (Buf, Ent);
+      end if;
       return +Buf;
    end Subprogram_Name;
 

Reply via email to