diff mbox

[Ada] Referenced enumeration literals in attributes.

Message ID 20111013102253.GA18455@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 13, 2011, 10:22 a.m. UTC
When an enumeration type appears in an attribute reference, all literals of
the type are marked as referenced. This must only be done if the attribute
reference appears in the current source. Else the information on references
may differ between a normal compilation and one that performs inlining.

No simple test available.

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

2011-10-13  Ed Schonberg  <schonberg@adacore.com>

	* sem_attr.adb (Check_Enum_Image, Analyze_Attribute case
	'Value): Mark literals as referenced only if reference is in
	current source unit.
diff mbox

Patch

Index: sem_attr.adb
===================================================================
--- sem_attr.adb	(revision 179894)
+++ sem_attr.adb	(working copy)
@@ -264,6 +264,10 @@ 
       --  If the prefix type is an enumeration type, set all its literals
       --  as referenced, since the image function could possibly end up
       --  referencing any of the literals indirectly. Same for Enum_Val.
+      --  Set the flag only if the reference is in the main code unit. Same
+      --  restriction when resolving 'Value; otherwise an improperly set
+      --  reference when analyzing an inlined body will lose a proper warning
+      --  on a useless with_clause.
 
       procedure Check_Fixed_Point_Type;
       --  Verify that prefix of attribute N is a fixed type
@@ -1226,7 +1230,9 @@ 
       procedure Check_Enum_Image is
          Lit : Entity_Id;
       begin
-         if Is_Enumeration_Type (P_Base_Type) then
+         if Is_Enumeration_Type (P_Base_Type)
+           and then In_Extended_Main_Code_Unit (N)
+         then
             Lit := First_Literal (P_Base_Type);
             while Present (Lit) loop
                Set_Referenced (Lit);
@@ -5031,7 +5037,9 @@ 
 
          --  Case of enumeration type
 
-         if Is_Enumeration_Type (P_Type) then
+         if Is_Enumeration_Type (P_Type)
+           and then In_Extended_Main_Code_Unit (N)
+         then
             Check_Restriction (No_Enumeration_Maps, N);
 
             --  Mark all enumeration literals as referenced, since the use of