diff mbox

[Ada] Handle some warning situations with Address aspect

Message ID 20131010105927.GA10979@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 10, 2013, 10:59 a.m. UTC
The Address attribute definition clause processing warns when overlaying
a small object with a large one, and also avoids giving a warning about
the entity not being referenced. This patch applies the same processing
to corresponding uses of the Address aspect. The following test program
shows the expected warnings being the same for the address aspect and
the address definition clause:

     1. function addrAP return Integer is
     2.    X : Integer := 123;
     3.    Y : Integer with Address => X'Address;
     4.    Z : Integer;
     5.    for Z'Address use X'Address;
     6.    P : Integer := 123;
     7.    Q : Long_Long_Integer;
     8.    for Q'Address use P'Address;
           |
        >>> warning: "Q" overlays smaller object
        >>> warning: program execution may be erroneous
        >>> warning: size of "Q" is 64
        >>> warning: size of "P" is 32

     9.    R : Long_Long_Integer with Address => P'Address;
                                      |
        >>> warning: "R" overlays smaller object
        >>> warning: program execution may be erroneous
        >>> warning: size of "R" is 64
        >>> warning: size of "P" is 32

    10. begin
    11.    return Y + Z;
    12. end addrAP;

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

2013-10-10  Robert Dewar  <dewar@adacore.com>

	* sem_ch13.adb (Analyze_Aspect_Specifications): For Address
	attribute, consider it to be set in source, because of aliasing
	considerations.
	(Analyze_Attribute_Definition_Clause): For the
	purpose of warning on overlays, take into account the aspect case.
diff mbox

Patch

Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb	(revision 203347)
+++ sem_ch13.adb	(working copy)
@@ -1593,6 +1593,18 @@ 
                      goto Continue;
                   end if;
 
+                  --  For case of address aspect, we don't consider that we
+                  --  know the entity is never set in the source, since it is
+                  --  is likely aliasing is occurring.
+
+                  --  Note: one might think that the analysis of the resulting
+                  --  attribute definition clause would take care of that, but
+                  --  that's not the case since it won't be from source.
+
+                  if A_Id = Aspect_Address then
+                     Set_Never_Set_In_Source (E, False);
+                  end if;
+
                   --  Construct the attribute definition clause
 
                   Aitem :=
@@ -3474,7 +3486,8 @@ 
                   --  and alignment of the overlaying variable. We defer this
                   --  check till after code generation to take full advantage
                   --  of the annotation done by the back end. This entry is
-                  --  only made if the address clause comes from source.
+                  --  only made if the address clause comes from source or
+                  --  from an aspect clause (which is still from source).
 
                   --  If the entity has a generic type, the check will be
                   --  performed in the instance if the actual type justifies
@@ -3482,7 +3495,8 @@ 
                   --  prevent spurious warnings.
 
                   if Address_Clause_Overlay_Warnings
-                    and then Comes_From_Source (N)
+                       and then (Comes_From_Source (N)
+                                  or else From_Aspect_Specification (N))
                     and then Present (O_Ent)
                     and then Is_Object (O_Ent)
                   then