public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] mips: Fix an ICE caused by r12-7962
@ 2022-04-02 10:53 Xi Ruoyao
  2022-04-02 10:59 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Xi Ruoyao @ 2022-04-02 10:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek, Richard Sandiford, YunQiang Su

I made a mistake in r12-7962 and it causes an ICE running g++.dg-struct-
layout-1 tests.  The fix and a reduced test are included in this patch.
Ok for trunk?

--------------------

DECL_SIZE(x) is NULL if x is a flexible array member, but I forgot to
check it in r12-7962.  Then if we increase the size of a struct with
flexible array member (by using aligned attribute), the code will
dereference NULL trying to use the "size" of the flexible array member.

gcc/

	* config/mips/mips.cc (mips_function_arg): Check if DECL_SIZE is
	NULL before dereferencing it.

gcc/testsuite/

	* gcc.target/mips/pr102024-4.c: New test.
---
 gcc/config/mips/mips.cc                    |  3 ++-
 gcc/testsuite/gcc.target/mips/pr102024-4.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/mips/pr102024-4.c

diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index a6dd1e9e7b6..079bb03968a 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -6082,7 +6082,8 @@ mips_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
 		     an ABI change.  */
 		  if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field))
 		    continue;
-		  if (integer_zerop (DECL_SIZE (field)))
+		  if (DECL_SIZE (field)
+		      && integer_zerop (DECL_SIZE (field)))
 		    {
 		      zero_width_field_abi_change = true;
 		      continue;
diff --git a/gcc/testsuite/gcc.target/mips/pr102024-4.c b/gcc/testsuite/gcc.target/mips/pr102024-4.c
new file mode 100644
index 00000000000..2147cc769d0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/pr102024-4.c
@@ -0,0 +1,10 @@
+// { dg-do compile }
+// { dg-options "-mabi=64 -mhard-float" }
+
+struct __attribute__((aligned(16))) test {
+  int x[0];
+  double b;
+  int f[];
+};
+
+void check(struct test) {} // { dg-message "the ABI for passing a value containing zero-width fields before an adjacent 64-bit floating-point field was changed in GCC 12.1" }
-- 
2.35.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mips: Fix an ICE caused by r12-7962
  2022-04-02 10:53 [PATCH] mips: Fix an ICE caused by r12-7962 Xi Ruoyao
@ 2022-04-02 10:59 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2022-04-02 10:59 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-patches, Jakub Jelinek, Richard Sandiford, YunQiang Su

On Sat, Apr 02, 2022 at 06:53:55PM +0800, Xi Ruoyao wrote:
> I made a mistake in r12-7962 and it causes an ICE running g++.dg-struct-
> layout-1 tests.  The fix and a reduced test are included in this patch.
> Ok for trunk?
> 
> --------------------
> 
> DECL_SIZE(x) is NULL if x is a flexible array member, but I forgot to
> check it in r12-7962.  Then if we increase the size of a struct with
> flexible array member (by using aligned attribute), the code will
> dereference NULL trying to use the "size" of the flexible array member.
> 
> gcc/
> 
> 	* config/mips/mips.cc (mips_function_arg): Check if DECL_SIZE is
> 	NULL before dereferencing it.
> 
> gcc/testsuite/
> 
> 	* gcc.target/mips/pr102024-4.c: New test.

Ok, sorry for not catching that.
All other targets guard such integer_zerop (DECL_SIZE (...)) uses
with either DECL_SIZE (...) != NULL_TREE or DECL_BIT_FIELD, so this is the
only such spot.

> diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
> index a6dd1e9e7b6..079bb03968a 100644
> --- a/gcc/config/mips/mips.cc
> +++ b/gcc/config/mips/mips.cc
> @@ -6082,7 +6082,8 @@ mips_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
>  		     an ABI change.  */
>  		  if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field))
>  		    continue;
> -		  if (integer_zerop (DECL_SIZE (field)))
> +		  if (DECL_SIZE (field)
> +		      && integer_zerop (DECL_SIZE (field)))
>  		    {
>  		      zero_width_field_abi_change = true;
>  		      continue;
> diff --git a/gcc/testsuite/gcc.target/mips/pr102024-4.c b/gcc/testsuite/gcc.target/mips/pr102024-4.c
> new file mode 100644
> index 00000000000..2147cc769d0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/mips/pr102024-4.c
> @@ -0,0 +1,10 @@
> +// { dg-do compile }
> +// { dg-options "-mabi=64 -mhard-float" }
> +
> +struct __attribute__((aligned(16))) test {
> +  int x[0];
> +  double b;
> +  int f[];
> +};
> +
> +void check(struct test) {} // { dg-message "the ABI for passing a value containing zero-width fields before an adjacent 64-bit floating-point field was changed in GCC 12.1" }
> -- 
> 2.35.1
> 

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-02 10:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-02 10:53 [PATCH] mips: Fix an ICE caused by r12-7962 Xi Ruoyao
2022-04-02 10:59 ` Jakub Jelinek

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).