From: Bob Duff Date: Wed, 14 Aug 2019 09:52:54 +0000 (+0000) Subject: [Ada] Alignment may be specified as zero X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ff0889eb4d7f34270a6cddb3351fe8ee4fc9bbe0;p=gcc.git [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 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 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 61c22fd146a..18877056574 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2019-08-14 Bob Duff + + * 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 * inline.adb (Add_Pending_Instantiation): Fix off-by-one error diff --git a/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst b/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst index 82dc97c34c9..efcdc8049fc 100644 --- a/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst +++ b/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst @@ -30,9 +30,11 @@ Alignment Clauses .. index:: Alignment Clause -GNAT requires that all alignment clauses specify a power of 2, and all -default alignments are always a power of 2. The default alignment -values are as follows: +GNAT requires that all alignment clauses specify 0 or a power of 2, and +all default alignments are always a power of 2. Specifying 0 is the +same as specifying 1. + +The default alignment values are as follows: * *Elementary Types*. @@ -610,23 +612,23 @@ alignment of the type (this is true for all types). In some cases the end record; -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 -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 -to have a component of type R in an array whose component size is -specified to be 40 bits. - -However, ``R'Object_Size`` will be 64 (bits). The difference is due to -the alignment requirement for objects of the record type. The X -component will require four-byte alignment because that is what type -Integer requires, whereas the Y component, a Character, will only -require 1-byte alignment. Since the alignment required for X is the -greatest of all the components' alignments, that is the alignment -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 -a multiple of the alignment value. Therefore, 40 bits rounded up to the -next multiple of 32 yields 64 bits. +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 +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 +to have a component of type R in an array whose component size is +specified to be 40 bits. + +However, ``R'Object_Size`` will be 64 (bits). The difference is due to +the alignment requirement for objects of the record type. The X +component will require four-byte alignment because that is what type +Integer requires, whereas the Y component, a Character, will only +require 1-byte alignment. Since the alignment required for X is the +greatest of all the components' alignments, that is the alignment +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 +a multiple of the alignment value. Therefore, 40 bits rounded up to the +next multiple of 32 yields 64 bits. For all other types, the ``Object_Size`` and ``Value_Size`` are the same (and equivalent to the RM attribute ``Size``). diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index 7de5de6ef4e..58ff6af0079 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -21,7 +21,7 @@ @copying @quotation -GNAT Reference Manual , Jul 31, 2019 +GNAT Reference Manual , Aug 01, 2019 AdaCore @@ -18369,9 +18369,11 @@ and this section describes the additional capabilities provided. @geindex Alignment Clause -GNAT requires that all alignment clauses specify a power of 2, and all -default alignments are always a power of 2. The default alignment -values are as follows: +GNAT requires that all alignment clauses specify 0 or a power of 2, and +all default alignments are always a power of 2. Specifying 0 is the +same as specifying 1. + +The default alignment values are as follows: @itemize * diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 8c5c4243e12..35a295c8cf3 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -11509,7 +11509,7 @@ package body Sem_Ch13 is if Align = No_Uint then return No_Uint; - elsif Align <= 0 then + elsif Align < 0 then -- This error is suppressed in ASIS mode to allow for different ASIS -- back ends or ASIS-based tools to query the illegal clause. @@ -11520,6 +11520,11 @@ package body Sem_Ch13 is 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 for J in Int range 0 .. 64 loop declare diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1b0c4a5d2b0..a9c98219a35 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-14 Bob Duff + + * gnat.dg/alignment15.adb: New testcase. + 2019-08-14 Bob Duff * gnat.dg/warn27.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/alignment15.adb b/gcc/testsuite/gnat.dg/alignment15.adb new file mode 100644 index 00000000000..e58243d2908 --- /dev/null +++ b/gcc/testsuite/gnat.dg/alignment15.adb @@ -0,0 +1,17 @@ +-- { 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;