]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix bugs relating to flexibly-sized objects in nios2 backend.
authorSandra Loosemore <sandra@codesourcery.com>
Tue, 3 Dec 2019 02:44:41 +0000 (21:44 -0500)
committerSandra Loosemore <sandra@gcc.gnu.org>
Tue, 3 Dec 2019 02:44:41 +0000 (21:44 -0500)
2019-12-02  Sandra Loosemore  <sandra@codesourcery.com>

Fix bugs relating to flexibly-sized objects in nios2 backend.

PR target/92499

gcc/c/
* c-decl.c (flexible_array_type_p): Move to common code.

gcc/
* config/nios2/nios2.c (nios2_in_small_data_p): Do not consider
objects of flexible types to be small if they have internal linkage
or are declared extern.
* config/nios2/nios2.h (ASM_OUTPUT_ALIGNED_LOCAL): Replace with...
(ASM_OUTPUT_ALIGNED_DECL_LOCAL): ...this.  Use targetm.in_small_data_p
instead of the size of the object initializer.
* tree.c (flexible_array_type_p): Move from C front end, and
generalize to handle fields in non-C structures.
* tree.h (flexible_array_type_p): Declare.

gcc/testsuite/
* gcc.target/nios2/pr92499-1.c: New.
* gcc.target/nios2/pr92499-2.c: New.
* gcc.target/nios2/pr92499-3.c: New.

From-SVN: r278919

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/config/nios2/nios2.c
gcc/config/nios2/nios2.h
gcc/testsuite/ChangeLog
gcc/tree.c
gcc/tree.h

index 1bb2099b0273e0613885c556761509e3bb41495b..ff257ff2449ac0a3f5a7ecd8e8851da4ac055d9f 100644 (file)
@@ -1,3 +1,18 @@
+2019-12-02  Sandra Loosemore  <sandra@codesourcery.com>
+
+       Fix bugs relating to flexibly-sized objects in nios2 backend.
+       
+       PR target/92499
+       * config/nios2/nios2.c (nios2_in_small_data_p): Do not consider
+       objects of flexible types to be small if they have internal linkage
+       or are declared extern.
+       * config/nios2/nios2.h (ASM_OUTPUT_ALIGNED_LOCAL): Replace with...
+       (ASM_OUTPUT_ALIGNED_DECL_LOCAL): ...this.  Use targetm.in_small_data_p
+       instead of the size of the object initializer.
+       * tree.c (flexible_array_type_p): Move from C front end, and
+       generalize to handle fields in non-C structures.
+       * tree.h (flexible_array_type_p): Declare.
+
 2019-12-02  Li Jia He  <helijia@linux.ibm.com>
 
        Partial backport from mainline
index 126a51e5748d0954c7bed806af9d1bfc941c1025..1295ca2c2a576d757c38ddaa1d2173192635b918 100644 (file)
@@ -1,3 +1,11 @@
+2019-12-02  Sandra Loosemore  <sandra@codesourcery.com>
+
+       Fix bugs relating to flexibly-sized objects in nios2 backend.
+       
+       PR target/92499
+
+       * c-decl.c (flexible_array_type_p): Move to common code.
+
 2019-10-21  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 04e0f4dc1981d1b2b49a4a40ec9326826f36900c..c423a0c41d2550e01cf1f87aa60a503a3992f3c2 100644 (file)
@@ -5586,39 +5586,6 @@ check_compound_literal_type (location_t loc, struct c_type_name *type_name)
                "defining a type in a compound literal is invalid in C++");
 }
 \f
-/* Determine whether TYPE is a structure with a flexible array member,
-   or a union containing such a structure (possibly recursively).  */
-
-static bool
-flexible_array_type_p (tree type)
-{
-  tree x;
-  switch (TREE_CODE (type))
-    {
-    case RECORD_TYPE:
-      x = TYPE_FIELDS (type);
-      if (x == NULL_TREE)
-       return false;
-      while (DECL_CHAIN (x) != NULL_TREE)
-       x = DECL_CHAIN (x);
-      if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
-         && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
-         && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
-         && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
-       return true;
-      return false;
-    case UNION_TYPE:
-      for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
-       {
-         if (flexible_array_type_p (TREE_TYPE (x)))
-           return true;
-       }
-      return false;
-    default:
-    return false;
-  }
-}
-\f
 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
    replacing with appropriate values if they are invalid.  */
 
index 1f00b8abbda6721d852b9a365e9474716e6cf835..5f62e643be237c9ce2ec355b45b586debe86328e 100644 (file)
@@ -2373,6 +2373,22 @@ nios2_in_small_data_p (const_tree exp)
          if (nios2_small_section_name_p (section))
            return true;
        }
+      else if (flexible_array_type_p (TREE_TYPE (exp))
+              && (!TREE_PUBLIC (exp) || DECL_EXTERNAL (exp)))
+       {
+         /* We really should not consider any objects of any flexibly-sized
+            type to be small data, but pre-GCC 10 did not test
+            for this and just fell through to the next case.  Thus older
+            code compiled with -mgpopt=global could contain GP-relative
+            accesses to objects defined in this compilation unit with
+            external linkage.  We retain the possible small-data treatment
+            of such definitions for backward ABI compatibility, but
+            no longer generate GP-relative accesses for external
+            references (so that the ABI could be changed in the future
+            with less potential impact), or objects with internal
+            linkage.  */
+         return false;
+       }
       else
        {
          HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
index 9dec57d67aecd1d699e0f6f4a88f94d7c475a30b..886716527073cb943c13ba21848e9ff6a384e449 100644 (file)
@@ -467,10 +467,10 @@ while (0)
    the linker seems to want the alignment of data objects
    to depend on their types.  We do exactly that here.  */
 
-#undef  ASM_OUTPUT_ALIGNED_LOCAL
-#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)               \
+#undef  ASM_OUTPUT_ALIGNED_DECL_LOCAL
+#define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN)   \
 do {                                                                    \
 if ((SIZE) <= nios2_section_threshold)                                \
if (targetm.in_small_data_p (DECL))                                   \
     switch_to_section (sbss_section);                                  \
   else                                                                  \
     switch_to_section (bss_section);                                   \
index 9285ba60ef22416cc11c293998a01c35a67b54e0..6a93f064568c90f25d613c1d1ab4acf1bd80546d 100644 (file)
@@ -1,3 +1,13 @@
+2019-12-02  Sandra Loosemore  <sandra@codesourcery.com>
+
+       Fix bugs relating to flexibly-sized objects in nios2 backend.
+       
+       PR target/92499
+
+       * gcc.target/nios2/pr92499-1.c: New.
+       * gcc.target/nios2/pr92499-2.c: New.
+       * gcc.target/nios2/pr92499-3.c: New.
+
 2019-12-02  Li Jia He  <helijia@linux.ibm.com>
 
        Partial backport from trunk
index 1549bde91473c883675e7f65dde0c281704abf46..028a2ed3bcad32d856c25cd417c10011849f6f0c 100644 (file)
@@ -14980,6 +14980,41 @@ default_is_empty_record (const_tree type)
   return default_is_empty_type (TYPE_MAIN_VARIANT (type));
 }
 
+/* Determine whether TYPE is a structure with a flexible array member,
+   or a union containing such a structure (possibly recursively).  */
+
+bool
+flexible_array_type_p (const_tree type)
+{
+  tree x, last;
+  switch (TREE_CODE (type))
+    {
+    case RECORD_TYPE:
+      last = NULL_TREE;
+      for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
+       if (TREE_CODE (x) == FIELD_DECL)
+         last = x;
+      if (last == NULL_TREE)
+       return false;
+      if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
+         && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
+         && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
+         && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
+       return true;
+      return false;
+    case UNION_TYPE:
+      for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
+       {
+         if (TREE_CODE (x) == FIELD_DECL
+             && flexible_array_type_p (TREE_TYPE (x)))
+           return true;
+       }
+      return false;
+    default:
+      return false;
+  }
+}
+
 /* Like int_size_in_bytes, but handle empty records specially.  */
 
 HOST_WIDE_INT
index 43dabd1a3bfa3380ad965b43dc532fe0c55e6730..2f8e37bb356fe8c9f43031eeaa8d501ec725605f 100644 (file)
@@ -5900,6 +5900,7 @@ extern void gt_pch_nx (tree &, gt_pointer_operator, void *);
 
 extern bool nonnull_arg_p (const_tree);
 extern bool default_is_empty_record (const_tree);
+extern bool flexible_array_type_p (const_tree);
 extern HOST_WIDE_INT arg_int_size_in_bytes (const_tree);
 extern tree arg_size_in_bytes (const_tree);
 extern bool expr_type_first_operand_type_p (tree_code);