From 4569f8b3652ae1e5ca353c24148b50c786b36c8b Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Sun, 1 Dec 2019 22:52:15 -0500 Subject: Fix bugs relating to flexibly-sized objects in nios2 backend. 2019-12-01 Sandra Loosemore 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: r278891 --- gcc/config/nios2/nios2.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gcc/config/nios2/nios2.c') diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c index 4cea0f4e2f2..ca6222658a9 100644 --- a/gcc/config/nios2/nios2.c +++ b/gcc/config/nios2/nios2.c @@ -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)); -- cgit v1.2.1