public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Referenced enumeration literals in attributes.
@ 2011-10-13 10:35 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2011-10-13 10:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 572 bytes --]

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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1518 bytes --]

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-10-13 10:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-13 10:35 [Ada] Referenced enumeration literals in attributes Arnaud Charlet

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