This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix bugs in handling of attributes (PR ada/9087)


Tested on i686-linux, committed on HEAD

This change makes the placement of the error message in the situation
described above more natural and more consistent with other errors
on attribute references.
Test case:
$ gcc -c pak.ads
must produce the error:
pak.ads:5:26: prefix of "Address" attribute cannot be overloaded
(previously the column number was 27 instead of 26).
with System;
package Pak is
   procedure P (X : Integer);
   procedure P (X : Boolean);
   A : System.Address := P'Address;
end Pak;

Secondly, fix an obscure case of a legal 'Size attribute reference
applied to an enumeration literal. A 'Size attribute reference with the
name of a parameterless function as its prefix must be interpreted as a
call to that function, which denotes an object, which is a legal prefix
for 'Size.
Test case:
$ gcc -c foo.adb
Compilation must succeed.
package foo is
   function T return BOOLEAN renames TRUE;
   function T1 return BOOLEAN;
   V1 : constant INTEGER := TRUE'Size;
   V2 : constant INTEGER := T'size;
   V3 : constant INTEGER := T'Alignment;
   V4 : constant STRING := T'Img;
   V5 : constant INTEGER := TRUE'Alignment;
   V6 : constant STRING := TRUE'Img;
   type Color is (Red, Green, Blue);
   V8 : constant Integer := Blue'Size;
end foo;
package body foo is
   function T1 return Boolean is begin return TRUE; end T1;
   V7 : constant INTEGER := T1'size;
end foo;

Thirdly, the GNAT front-end performs simple constant-folding on expressions
that are not static by the RM definition. The resulting value propagation is
legal as long as the expression itself is recognized as non-static. In
the case of attributes of arrays with static bounds, the expression is
static if the prefix of the attribute statically denotes an entity, see
RM95, 4.9 (14). GNAT improperly extended the staticness to any array
object with static bounds, including record components. This patch fixes
this unwarranted generalization. The following program must be rejected:
--
gcc -c case_error.adb
--
case_error.adb:5:13: missing case value: "None"
--
package Case_Error is
   type Dock_Side is (Left, Right, Top, Bottom, None);
   type Object_Access is access Integer;
   type Notebook_Array is array (Left .. Bottom) of Object_Access;
   type Mdi_Window_Record is record
      Docks : Notebook_Array := (others => null);
   end record;
   procedure The_Failure (Mdi : access Mdi_Window_Record);
end Case_Error;
package body Case_Error is
  procedure The_Failure (Mdi : access Mdi_Window_Record) is
  begin
     for Side in Mdi.Docks'Range loop
        case Side is
          when Left | Right => null;
          when Top | Bottom => null;
        end case;
     end loop;
  end The_Failure;
end Case_Error;

Finally, fix also PR ada/9087
The problem was that the circuitry in Eval_Attr was failing to properly
evaluate Component_Size for unconstrained array types. This was not just
an efficiency issue, since the result was passed to the back end, and
for packed types, the back end does not correctly compute the component
size (since it works with the equivalent Packed Array Type (PAT) which
is always an array of bytes.

The following test program:

with Ada.Text_IO; use Ada.Text_IO;
with System; use System;

procedure karl is
   type unconstrained_array is array (Positive range <>) of Boolean;
   for unconstrained_array'Component_Size use 1;

   pragma Pack (unconstrained_array);
   type ucs_array_ptr is access unconstrained_array;
   A : ucs_array_ptr := new unconstrained_array (1 .. 100);

begin
   Put_Line (Integer'Image (unconstrained_array'Component_Size));

   if (A (1)'Address = A (5)'Address) then
      Put_Line ("A (1) and A (5) are within the same byte");
   end if;
end karl;

Should execute with the output:

 1
A (1) and A (5) are within the same byte

(before the fix, the first line output 8)

2005-09-01  Thomas Quinot  <quinot@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>
	    Robert Dewar  <dewar@adacore.com>

	* sem_attr.adb (Resolve_Attribute, case 'Address): For an illegal
	'Address attribute reference with an overloaded prefix, use the
	location of the prefix (not the location of the attribute reference) as
	the error location.
	(Analyze_Attribute, case 'Size): The name of an enumeration literal, or
	a function renaming thereof, is a valid prefix for 'Size (where it is
	intepreted as a function call).
	(Statically_Denotes_Entity): New predicate to determine whether the
	prefix of an array attribute can be considered static.

	PR ada/9087
	(Eval_Attr): Fix failure to evaluate Component_Size for
	unconstrained arrays (resulted in wrong value in packed case, since
	back end cannot handle this case)

Attachment: difs.30
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]