diff mbox

[Ada] Protect generation of Alfa sections in ALI files against empty node

Message ID 20120330091355.GA18297@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet March 30, 2012, 9:13 a.m. UTC
In some cases, a node designating a compilation unit may be empty, which was
not considered in the code generating Alfa sections in ALI files. Now corrected.

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

2012-03-30  Yannick Moy  <moy@adacore.com>

	* lib-xref-alfa.adb (Add_Alfa_File): Take into account possible absence
	of compilation unit for unit in Sdep_Table.
diff mbox

Patch

Index: lib-xref-alfa.adb
===================================================================
--- lib-xref-alfa.adb	(revision 185995)
+++ lib-xref-alfa.adb	(working copy)
@@ -226,9 +226,15 @@ 
 
       From := Alfa_Scope_Table.Last + 1;
 
-      Traverse_Compilation_Unit (Cunit (U), Detect_And_Add_Alfa_Scope'Access,
-                                 Inside_Stubs => False);
+      --  Unit U might not have an associated compilation unit, as seen in code
+      --  filling Sdep_Table in Write_ALI.
 
+      if Present (Cunit (U)) then
+         Traverse_Compilation_Unit (Cunit (U),
+                                    Detect_And_Add_Alfa_Scope'Access,
+                                    Inside_Stubs => False);
+      end if;
+
       --  Update scope numbers
 
       declare
@@ -279,9 +285,11 @@ 
       Get_Name_String (Reference_Name (S));
       File_Name := new String'(Name_Buffer (1 .. Name_Len));
 
-      --  For subunits, also retrieve the file name of the unit
+      --  For subunits, also retrieve the file name of the unit. Only do so if
+      --  unit U has an associated compilation unit.
 
-      if Present (Cunit (Unit (S)))
+      if Present (Cunit (U))
+        and then Present (Cunit (Unit (S)))
         and then Nkind (Unit (Cunit (Unit (S)))) = N_Subunit
       then
          Get_Name_String (Reference_Name (Main_Source_File));