[gcc r11-3108] Fix bogus error on Value_Size clause for variant record type

Eric Botcazou ebotcazou@gcc.gnu.org
Thu Sep 10 16:01:30 GMT 2020


https://gcc.gnu.org/g:e63eb26d22dbbbbb67f7f240ea5a7234cd2498cb

commit r11-3108-ge63eb26d22dbbbbb67f7f240ea5a7234cd2498cb
Author: Eric Botcazou <ebotcazou@gcc.gnu.org>
Date:   Thu Sep 10 17:59:11 2020 +0200

    Fix bogus error on Value_Size clause for variant record type
    
    This is a regression present on the mainline and 10 branch: the compiler
    rejects a Value_Size clause on a discriminated record type with variant.
    
    gcc/ada/ChangeLog:
            * gcc-interface/decl.c (set_rm_size): Do not take into account the
            Value_Size clause if it is not for the entity itself.
    
    gcc/testsuite/ChangeLog:
            * gnat.dg/specs/size_clause5.ads: New test.

Diff:
---
 gcc/ada/gcc-interface/decl.c                 |  6 ++++--
 gcc/testsuite/gnat.dg/specs/size_clause5.ads | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index f85b2b5bbbb..8045fa5ff97 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -9083,10 +9083,12 @@ set_rm_size (Uint uint_size, tree gnu_type, Entity_Id gnat_entity)
   if (uint_size == No_Uint)
     return;
 
-  /* Only issue an error if a Value_Size clause was explicitly given.
-     Otherwise, we'd be duplicating an error on the Size clause.  */
+  /* Only issue an error if a Value_Size clause was explicitly given for the
+     entity; otherwise, we'd be duplicating an error on the Size clause.  */
   gnat_attr_node
     = Get_Attribute_Definition_Clause (gnat_entity, Attr_Value_Size);
+  if (Present (gnat_attr_node) && Entity (gnat_attr_node) != gnat_entity)
+    gnat_attr_node = Empty;
 
   /* Get the size as an INTEGER_CST.  Issue an error if a size was specified
      but cannot be represented in bitsizetype.  */
diff --git a/gcc/testsuite/gnat.dg/specs/size_clause5.ads b/gcc/testsuite/gnat.dg/specs/size_clause5.ads
new file mode 100644
index 00000000000..ba45bbfa09d
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/size_clause5.ads
@@ -0,0 +1,16 @@
+-- { dg-do compile }
+
+package Size_Clause5 is
+
+  type Arr is array (1 .. 16) of Boolean;
+
+  type RRec (D : Boolean) is record
+    case D is
+      when True =>  I : Integer;
+      when False => A : Arr;
+    end case;
+  end record;
+  for RRec'Object_Size use 160;
+  for RRec'Value_Size use 160;
+
+end Size_Clause5;


More information about the Gcc-cvs mailing list