[Ada] Object_Size clause specifying 0 bits is illegal
authorBob Duff <duff@adacore.com>
Tue, 20 Aug 2019 09:48:57 +0000 (09:48 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 20 Aug 2019 09:48:57 +0000 (09:48 +0000)
The patch gives an error message on "for T'Object_Size use 0;".

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

gcc/ada/

* sem_ch13.adb (Object_Size): Give an error for zero. It really
rubs me the wrong way that we don't honor "for T'Object_Size use
0;", but it's not important enough to fix. In any case, if we're
not going to obey the clause, we should give an error.

gcc/testsuite/

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

From-SVN: r274722

gcc/ada/ChangeLog
gcc/ada/sem_ch13.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/object_size1.adb [new file with mode: 0644]

index 558d5e072d2c4493daefca3a8cc9c82cf313a0c3..61befab3f33a56482c930187bf5c675a5d897385 100644 (file)
@@ -1,3 +1,10 @@
+2019-08-20  Bob Duff  <duff@adacore.com>
+
+       * sem_ch13.adb (Object_Size): Give an error for zero. It really
+       rubs me the wrong way that we don't honor "for T'Object_Size use
+       0;", but it's not important enough to fix. In any case, if we're
+       not going to obey the clause, we should give an error.
+
 2019-08-20  Bob Duff  <duff@adacore.com>
 
        * errout.adb (Error_Msg_Internal): Set Warn_Err in case of
index 4a07478757da3835e1ebc566e41f466bdc7449f6..dec542b1d891d0e9fc09da121a26009f8b55ac0a 100644 (file)
@@ -5812,6 +5812,9 @@ package body Sem_Ch13 is
                if ASIS_Mode then
                   null;
 
+               elsif Size <= 0 then
+                  Error_Msg_N ("Object_Size must be positive", Expr);
+
                elsif Is_Scalar_Type (U_Ent) then
                   if Size /= 8 and then Size /= 16 and then Size /= 32
                     and then UI_Mod (Size, 64) /= 0
index e4cc820f0f71a163d837ba8409f88b89b3bac96e..89406642e92fdac5577c12e8c9b75c8f3531f551 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-20  Bob Duff  <duff@adacore.com>
+
+       * gnat.dg/object_size1.adb: New testcase.
+
 2019-08-20  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.c-torture/execute/20190820-1.c: New test.
diff --git a/gcc/testsuite/gnat.dg/object_size1.adb b/gcc/testsuite/gnat.dg/object_size1.adb
new file mode 100644 (file)
index 0000000..85c6962
--- /dev/null
@@ -0,0 +1,13 @@
+--  { dg-do compile }
+
+with Text_IO; use Text_IO;
+
+procedure Object_Size1 is
+  type Zero_Size_Type is (Solo);
+
+  for Zero_Size_Type'Size use 0;
+  for Zero_Size_Type'Object_Size use 0;  --  { dg-error "Object_Size must be positive" }
+begin
+  Put_Line (Zero_Size_Type'Size'Image);
+  Put_Line (Zero_Size_Type'Object_Size'Image);
+end Object_Size1;