aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2019-08-14 09:52:54 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-08-14 09:52:54 +0000
commitff0889eb4d7f34270a6cddb3351fe8ee4fc9bbe0 (patch)
tree5aef1abe0c82b06992ba02189c10df55d9cdcef7 /gcc
parentf0539a7914cba3b7de76665a74edb90e30f2dbc9 (diff)
downloadgcc-ff0889eb4d7f34270a6cddb3351fe8ee4fc9bbe0.zip
gcc-ff0889eb4d7f34270a6cddb3351fe8ee4fc9bbe0.tar.gz
gcc-ff0889eb4d7f34270a6cddb3351fe8ee4fc9bbe0.tar.bz2
[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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog8
-rw-r--r--gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst42
-rw-r--r--gcc/ada/gnat_rm.texi10
-rw-r--r--gcc/ada/sem_ch13.adb7
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/alignment15.adb17
6 files changed, 63 insertions, 25 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 61c22fd..1887705 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,11 @@
+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>
* 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 82dc97c..efcdc80 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 7de5de6..58ff6af 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 8c5c424..35a295c 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 1b0c4a5..a9c9821 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
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.
2019-08-14 Bob Duff <duff@adacore.com>
diff --git a/gcc/testsuite/gnat.dg/alignment15.adb b/gcc/testsuite/gnat.dg/alignment15.adb
new file mode 100644
index 0000000..e58243d
--- /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;