diff mbox series

[Ada] Fix bogus error on Value_Size clause for variant record type

Message ID 33357139.DhnpTUTRLS@fomalhaut
State New
Headers show
Series [Ada] Fix bogus error on Value_Size clause for variant record type | expand

Commit Message

Eric Botcazou Sept. 10, 2020, 4:05 p.m. UTC
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.

Tested on x86_64-suse-linux, applied on mainline and 10 branch.


2020-09-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (set_rm_size): Do not take into account the
	Value_Size clause if it is not for the entity itself.


2020-09-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/specs/size_clause5.ads: New test.
diff mbox series

Patch

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.  */