Commit ff0889eb by Bob Duff Committed by Pierre-Marie de Rodat

[Ada] Alignment may be specified as zero

An Alignment clause or an aspect_specification for Alignment may be
specified as 0, which is treated the same as 1.

2019-08-14  Bob Duff  <duff@adacore.com>

gcc/ada/

	* sem_ch13.adb (Get_Alignment_Value): Return 1 for Alignment 0,
	and do not give an error.
	* doc/gnat_rm/representation_clauses_and_pragmas.rst: Update the
	corresponding documentation.
	* gnat_rm.texi: Regenerate.

gcc/testsuite/

	* gnat.dg/alignment15.adb: New testcase.

From-SVN: r274473
parent f0539a79
2019-08-14 Bob Duff <duff@adacore.com>
* sem_ch13.adb (Get_Alignment_Value): Return 1 for Alignment 0,
and do not give an error.
* doc/gnat_rm/representation_clauses_and_pragmas.rst: Update the
corresponding documentation.
* gnat_rm.texi: Regenerate.
2019-08-14 Eric Botcazou <ebotcazou@adacore.com> 2019-08-14 Eric Botcazou <ebotcazou@adacore.com>
* inline.adb (Add_Pending_Instantiation): Fix off-by-one error * inline.adb (Add_Pending_Instantiation): Fix off-by-one error
......
...@@ -30,9 +30,11 @@ Alignment Clauses ...@@ -30,9 +30,11 @@ Alignment Clauses
.. index:: Alignment Clause .. index:: Alignment Clause
GNAT requires that all alignment clauses specify a power of 2, and all GNAT requires that all alignment clauses specify 0 or a power of 2, and
default alignments are always a power of 2. The default alignment all default alignments are always a power of 2. Specifying 0 is the
values are as follows: same as specifying 1.
The default alignment values are as follows:
* *Elementary Types*. * *Elementary Types*.
...@@ -610,23 +612,23 @@ alignment of the type (this is true for all types). In some cases the ...@@ -610,23 +612,23 @@ alignment of the type (this is true for all types). In some cases the
end record; end record;
On a typical 32-bit architecture, the X component will occupy four bytes On a typical 32-bit architecture, the X component will occupy four bytes
and the Y component will occupy one byte, for a total of 5 bytes. As a and the Y component will occupy one byte, for a total of 5 bytes. As a
result ``R'Value_Size`` will be 40 (bits) since this is the minimum size result ``R'Value_Size`` will be 40 (bits) since this is the minimum size
required to store a value of this type. For example, it is permissible required to store a value of this type. For example, it is permissible
to have a component of type R in an array whose component size is to have a component of type R in an array whose component size is
specified to be 40 bits. specified to be 40 bits.
However, ``R'Object_Size`` will be 64 (bits). The difference is due to However, ``R'Object_Size`` will be 64 (bits). The difference is due to
the alignment requirement for objects of the record type. The X the alignment requirement for objects of the record type. The X
component will require four-byte alignment because that is what type component will require four-byte alignment because that is what type
Integer requires, whereas the Y component, a Character, will only Integer requires, whereas the Y component, a Character, will only
require 1-byte alignment. Since the alignment required for X is the require 1-byte alignment. Since the alignment required for X is the
greatest of all the components' alignments, that is the alignment greatest of all the components' alignments, that is the alignment
required for the enclosing record type, i.e., 4 bytes or 32 bits. As required for the enclosing record type, i.e., 4 bytes or 32 bits. As
indicated above, the actual object size must be rounded up so that it is indicated above, the actual object size must be rounded up so that it is
a multiple of the alignment value. Therefore, 40 bits rounded up to the a multiple of the alignment value. Therefore, 40 bits rounded up to the
next multiple of 32 yields 64 bits. next multiple of 32 yields 64 bits.
For all other types, the ``Object_Size`` For all other types, the ``Object_Size``
and ``Value_Size`` are the same (and equivalent to the RM attribute ``Size``). and ``Value_Size`` are the same (and equivalent to the RM attribute ``Size``).
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
@copying @copying
@quotation @quotation
GNAT Reference Manual , Jul 31, 2019 GNAT Reference Manual , Aug 01, 2019
AdaCore AdaCore
...@@ -18369,9 +18369,11 @@ and this section describes the additional capabilities provided. ...@@ -18369,9 +18369,11 @@ and this section describes the additional capabilities provided.
@geindex Alignment Clause @geindex Alignment Clause
GNAT requires that all alignment clauses specify a power of 2, and all GNAT requires that all alignment clauses specify 0 or a power of 2, and
default alignments are always a power of 2. The default alignment all default alignments are always a power of 2. Specifying 0 is the
values are as follows: same as specifying 1.
The default alignment values are as follows:
@itemize * @itemize *
...@@ -11509,7 +11509,7 @@ package body Sem_Ch13 is ...@@ -11509,7 +11509,7 @@ package body Sem_Ch13 is
if Align = No_Uint then if Align = No_Uint then
return No_Uint; return No_Uint;
elsif Align <= 0 then elsif Align < 0 then
-- This error is suppressed in ASIS mode to allow for different ASIS -- This error is suppressed in ASIS mode to allow for different ASIS
-- back ends or ASIS-based tools to query the illegal clause. -- back ends or ASIS-based tools to query the illegal clause.
...@@ -11520,6 +11520,11 @@ package body Sem_Ch13 is ...@@ -11520,6 +11520,11 @@ package body Sem_Ch13 is
return No_Uint; return No_Uint;
-- If Alignment is specified to be 0, we treat it the same as 1
elsif Align = 0 then
return Uint_1;
else else
for J in Int range 0 .. 64 loop for J in Int range 0 .. 64 loop
declare declare
......
2019-08-14 Bob Duff <duff@adacore.com> 2019-08-14 Bob Duff <duff@adacore.com>
* gnat.dg/alignment15.adb: New testcase.
2019-08-14 Bob Duff <duff@adacore.com>
* gnat.dg/warn27.adb: New testcase. * gnat.dg/warn27.adb: New testcase.
2019-08-14 Bob Duff <duff@adacore.com> 2019-08-14 Bob Duff <duff@adacore.com>
......
-- { dg-compile }
procedure Alignment15 is
type T0 is record
X : Integer;
end record;
for T0'Alignment use 0;
type T00 is record
X : Integer;
end record with Alignment => 0;
Dummy0 : T0;
Dummy00 : T00;
begin
null;
end;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment