public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5748] [Ada] Fix packing for array component with discriminated part
@ 2021-12-02 16:30 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-12-02 16:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5a11ffadf58a3668655e08f610281ac5567b4d93

commit r12-5748-g5a11ffadf58a3668655e08f610281ac5567b4d93
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Wed Nov 17 00:09:56 2021 +0100

    [Ada] Fix packing for array component with discriminated part
    
    gcc/ada/
    
            * gcc-interface/gigi.h (aggregate_type_contains_array_p): Delete.
            (type_has_variable_size): Declare.
            * gcc-interface/decl.c (adjust_packed): Return 0 only if the field
            type is an array with variable size.
            * gcc-interface/utils.c (aggregate_type_contains_array_p): Make
            static and remove SELF_REFERENTIAL parameter.
            (type_has_variable_size): Make public.
            (create_field_decl): Adjust call to aggregate_type_contains_array_p.

Diff:
---
 gcc/ada/gcc-interface/decl.c  | 13 ++++++-------
 gcc/ada/gcc-interface/gigi.h  |  7 +++----
 gcc/ada/gcc-interface/utils.c | 17 +++++++----------
 3 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index 3d14b5feb32..f0c17fc5eab 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -7221,13 +7221,12 @@ choices_to_gnu (tree gnu_operand, Node_Id gnat_choices)
 static int
 adjust_packed (tree field_type, tree record_type, int packed)
 {
-  /* If the field contains an array with self-referential size, we'd better
-     not pack it because this would misalign it and, therefore, cause large
-     temporaries to be created in case we need to take the address of the
-     field.  See addressable_p and the notes on the addressability issues
-     for further details.  */
-  if (AGGREGATE_TYPE_P (field_type)
-      && aggregate_type_contains_array_p (field_type, true))
+  /* If the field is an array of variable size, we'd better not pack it because
+     this would misalign it and, therefore, probably cause large temporarie to
+     be created in case we need to take its address.  See addressable_p and the
+     notes on the addressability issues for further details.  */
+  if (TREE_CODE (field_type) == ARRAY_TYPE
+      && type_has_variable_size (field_type))
     return 0;
 
   /* In the other cases, we can honor the packing.  */
diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h
index 1b55ec55df4..4b4a14dd3c6 100644
--- a/gcc/ada/gcc-interface/gigi.h
+++ b/gcc/ada/gcc-interface/gigi.h
@@ -838,10 +838,9 @@ extern tree get_base_type (tree type);
    in bits.  If we don't know anything about the alignment, return 0.  */
 extern unsigned int known_alignment (tree exp);
 
-/* Return true if TYPE, an aggregate type, contains (or is) an array.
-   If SELF_REFERENTIAL is true, then an additional requirement on the
-   array is that it be self-referential.  */
-extern bool aggregate_type_contains_array_p (tree type, bool self_referential);
+/* Return true if TYPE is a type with variable size or a padding type with a
+   field of variable size or a record that has a field with such a type.  */
+extern bool type_has_variable_size (tree type);
 
 /* Return true if VALUE is a multiple of FACTOR. FACTOR must be a power
    of 2.  */
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index ab5ca5b1714..d5dd04a4fe7 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -2902,12 +2902,10 @@ create_var_decl (tree name, tree asm_name, tree type, tree init,
   return var_decl;
 }
 
-/* Return true if TYPE, an aggregate type, contains (or is) an array.
-   If SELF_REFERENTIAL is true, then an additional requirement on the
-   array is that it be self-referential.  */
+/* Return true if TYPE, an aggregate type, contains (or is) an array.  */
 
-bool
-aggregate_type_contains_array_p (tree type, bool self_referential)
+static bool
+aggregate_type_contains_array_p (tree type)
 {
   switch (TREE_CODE (type))
     {
@@ -2918,14 +2916,13 @@ aggregate_type_contains_array_p (tree type, bool self_referential)
 	tree field;
 	for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
 	  if (AGGREGATE_TYPE_P (TREE_TYPE (field))
-	      && aggregate_type_contains_array_p (TREE_TYPE (field),
-						  self_referential))
+	      && aggregate_type_contains_array_p (TREE_TYPE (field)))
 	    return true;
 	return false;
       }
 
     case ARRAY_TYPE:
-      return self_referential ? type_contains_placeholder_p (type) : true;
+      return true;
 
     default:
       gcc_unreachable ();
@@ -2935,7 +2932,7 @@ aggregate_type_contains_array_p (tree type, bool self_referential)
 /* Return true if TYPE is a type with variable size or a padding type with a
    field of variable size or a record that has a field with such a type.  */
 
-static bool
+bool
 type_has_variable_size (tree type)
 {
   tree field;
@@ -3037,7 +3034,7 @@ create_field_decl (tree name, tree type, tree record_type, tree size, tree pos,
 		 || (!pos && type_has_variable_size (type))
 		 || (!pos
 		     && AGGREGATE_TYPE_P (type)
-		     && aggregate_type_contains_array_p (type, false))))
+		     && aggregate_type_contains_array_p (type))))
     SET_DECL_ALIGN (field_decl, BITS_PER_UNIT);
 
   /* Bump the alignment if need be, either for bitfield/packing purposes or


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-02 16:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 16:30 [gcc r12-5748] [Ada] Fix packing for array component with discriminated part Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).