]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix segfault at run time on strict-alignment platforms
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 21 May 2021 08:40:41 +0000 (10:40 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 21 May 2021 08:42:10 +0000 (10:42 +0200)
This fixes a regression present on the mainline and 11 branch by
restricting the problematic change dealing with bitfields whose
nomimal subtype is self-referential to the cases where the size
is really lower.

gcc/ada/
* gcc-interface/trans.c (Call_to_gnu): Restrict previous change
to bitfields whose size is not equal to the type size.
(gnat_to_gnu): Likewise.

gcc/ada/gcc-interface/trans.c

index 8d63d03079f96a1e1f92f3e082e9cb7ddbc12f17..d4435eab10aec4c86eac7974ba35ece0df690570 100644 (file)
@@ -4553,6 +4553,8 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target,
          || (gnu_target
              && TREE_CODE (gnu_target) == COMPONENT_REF
              && DECL_BIT_FIELD (TREE_OPERAND (gnu_target, 1))
+             && DECL_SIZE (TREE_OPERAND (gnu_target, 1))
+                != TYPE_SIZE (TREE_TYPE (gnu_target))
              && type_is_padding_self_referential (gnu_result_type))))
     {
       gnu_retval = create_temporary ("R", gnu_result_type);
@@ -8271,7 +8273,9 @@ gnat_to_gnu (Node_Id gnat_node)
         much data.  But do not remove it if it is already too small.  */
       if (type_is_padding_self_referential (TREE_TYPE (gnu_result))
          && !(TREE_CODE (gnu_result) == COMPONENT_REF
-              && DECL_BIT_FIELD (TREE_OPERAND (gnu_result, 1))))
+              && DECL_BIT_FIELD (TREE_OPERAND (gnu_result, 1))
+              && DECL_SIZE (TREE_OPERAND (gnu_result, 1))
+                 != TYPE_SIZE (TREE_TYPE (gnu_result))))
        gnu_result = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_result))),
                              gnu_result);
     }