Avoid ICE with m68k-elf -malign-int and libcalls

Message ID 20240104092425.1844-2-mikpelinux@gmail.com
State Accepted
Headers
Series Avoid ICE with m68k-elf -malign-int and libcalls |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Mikael Pettersson Jan. 4, 2024, 9:23 a.m. UTC
  emit_library_call_value_1 calls emit_push_insn with NULL_TREE
for TYPE.  Sometimes emit_push_insn needs to assign a temp with
that TYPE, which causes a segfault.

Fixed by computing the TYPE from MODE when needed.

Original patch by Thorsten Otto.

gcc/

2024-01-03  Thorsten Otto  <admin@tho-otto.de>
            Mikael Pettersson  <mikpelinux@gmail.com>

	PR target/82420
	PR target/111279
	* expr.cc (emit_push_insn): If TYPE is NULL compute it
	from MODE before calling assign_temp.

gcc/teststuite/

2024-01-03  Mikael Pettersson  <mikpelinux@gmail.com>

	PR target/82420
	* gcc.target/m68k/pr82420.c: New test.
---
 gcc/expr.cc                             | 6 +++++-
 gcc/testsuite/gcc.target/m68k/pr82420.c | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/m68k/pr82420.c
  

Comments

Jeff Law Jan. 4, 2024, 9:39 p.m. UTC | #1
On 1/4/24 02:23, Mikael Pettersson wrote:
> emit_library_call_value_1 calls emit_push_insn with NULL_TREE
> for TYPE.  Sometimes emit_push_insn needs to assign a temp with
> that TYPE, which causes a segfault.
> 
> Fixed by computing the TYPE from MODE when needed.
> 
> Original patch by Thorsten Otto.
> 
> gcc/
> 
> 2024-01-03  Thorsten Otto  <admin@tho-otto.de>
>              Mikael Pettersson  <mikpelinux@gmail.com>
> 
> 	PR target/82420
> 	PR target/111279
> 	* expr.cc (emit_push_insn): If TYPE is NULL compute it
> 	from MODE before calling assign_temp.
> 
> gcc/teststuite/
> 
> 2024-01-03  Mikael Pettersson  <mikpelinux@gmail.com>
> 
> 	PR target/82420
> 	* gcc.target/m68k/pr82420.c: New test.
This really needs to happen in the two call paths which pass in 
NULL_TREE for the type.  Note how the type is used to determine padding 
earlier in emit_push_insn.  That would also make the code more 
consistent with the comment before emit_push_insn which implies that 
both MODE and TYPE are valid.


Additionally you should bootstrap and regression test this patch on at 
least one target.

jeff
  
Mikael Pettersson Jan. 16, 2024, 4:55 p.m. UTC | #2
On Thu, 4 Jan 2024 14:39:23 -0700, Jeff Law wrote:
> On 1/4/24 02:23, Mikael Pettersson wrote:
> > emit_library_call_value_1 calls emit_push_insn with NULL_TREE
> > for TYPE.  Sometimes emit_push_insn needs to assign a temp with
> > that TYPE, which causes a segfault.
> > 
> > Fixed by computing the TYPE from MODE when needed.
> > 
> > Original patch by Thorsten Otto.
> > 
> > gcc/
> > 
> > 2024-01-03  Thorsten Otto  <admin@tho-otto.de>
> >              Mikael Pettersson  <mikpelinux@gmail.com>
> > 
> > 	PR target/82420
> > 	PR target/111279
> > 	* expr.cc (emit_push_insn): If TYPE is NULL compute it
> > 	from MODE before calling assign_temp.
> > 
> > gcc/teststuite/
> > 
> > 2024-01-03  Mikael Pettersson  <mikpelinux@gmail.com>
> > 
> > 	PR target/82420
> > 	* gcc.target/m68k/pr82420.c: New test.
> This really needs to happen in the two call paths which pass in 
> NULL_TREE for the type.  Note how the type is used to determine padding 
> earlier in emit_push_insn.  That would also make the code more 
> consistent with the comment before emit_push_insn which implies that 
> both MODE and TYPE are valid.
> 
> 
> Additionally you should bootstrap and regression test this patch on at 
> least one target.

Updated as requested, and bootstrapped and tested on
{x86_64,aarch64,m68k}-linux-gnu without regressions.

gcc/

2024-01-16  Thorsten Otto  <admin@tho-otto.de>
            Mikael Pettersson  <mikpelinux@gmail.com>

	PR target/82420
	PR target/111279
	* calls.cc (emit_library_call_value_1): Pass valid TYPE
	to emit_push_insn.
	* expr.cc (emit_push_insn): Likewise.

gcc/teststuite/

2024-01-16  Mikael Pettersson  <mikpelinux@gmail.com>

	PR target/82420
	* gcc.target/m68k/pr82420.c: New test.
---
 gcc/calls.cc                            | 4 ++--
 gcc/expr.cc                             | 5 +++--
 gcc/testsuite/gcc.target/m68k/pr82420.c | 9 +++++++++
 3 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/m68k/pr82420.c

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 7c35b1ad204..01f44734743 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -4580,8 +4580,8 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
 		}
 	    }
 
-	  emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
-			  partial, reg, 0, argblock,
+	  emit_push_insn (val, mode, lang_hooks.types.type_for_mode (mode, 0),
+			  NULL_RTX, parm_align, partial, reg, 0, argblock,
 			  (gen_int_mode
 			   (argvec[argnum].locate.offset.constant, Pmode)),
 			  reg_parm_stack_space,
diff --git a/gcc/expr.cc b/gcc/expr.cc
index 34f5ff90a9f..3015f9e51d8 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -5532,11 +5532,12 @@ emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
       /* Loop over all the words allocated on the stack for this arg.  */
       /* We can do it by words, because any scalar bigger than a word
 	 has a size a multiple of a word.  */
+      tree word_mode_type = lang_hooks.types.type_for_mode (word_mode, 1);
       for (i = num_words - 1; i >= not_stack; i--)
 	if (i >= not_stack + offset)
 	  if (!emit_push_insn (operand_subword_force (x, i, mode),
-			  word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
-			  0, args_addr,
+			  word_mode, word_mode_type, NULL_RTX, align, 0,
+			  NULL_RTX, 0, args_addr,
 			  GEN_INT (args_offset + ((i - not_stack + skip)
 						  * UNITS_PER_WORD)),
 			  reg_parm_stack_space, alignment_pad, sibcall_p))
diff --git a/gcc/testsuite/gcc.target/m68k/pr82420.c b/gcc/testsuite/gcc.target/m68k/pr82420.c
new file mode 100644
index 00000000000..5c84f292103
--- /dev/null
+++ b/gcc/testsuite/gcc.target/m68k/pr82420.c
@@ -0,0 +1,9 @@
+/* { do-do compile } */
+/* { dg-options "-march=68000 -malign-int" } */
+
+int a;
+
+void f(void)
+{
+    a /= 3;
+}
  
Mikael Pettersson Jan. 16, 2024, 4:55 p.m. UTC | #3
On Thu, 4 Jan 2024 14:39:23 -0700, Jeff Law wrote:
> On 1/4/24 02:23, Mikael Pettersson wrote:
> > emit_library_call_value_1 calls emit_push_insn with NULL_TREE
> > for TYPE.  Sometimes emit_push_insn needs to assign a temp with
> > that TYPE, which causes a segfault.
> > 
> > Fixed by computing the TYPE from MODE when needed.
> > 
> > Original patch by Thorsten Otto.
> > 
> > gcc/
> > 
> > 2024-01-03  Thorsten Otto  <admin@tho-otto.de>
> >              Mikael Pettersson  <mikpelinux@gmail.com>
> > 
> > 	PR target/82420
> > 	PR target/111279
> > 	* expr.cc (emit_push_insn): If TYPE is NULL compute it
> > 	from MODE before calling assign_temp.
> > 
> > gcc/teststuite/
> > 
> > 2024-01-03  Mikael Pettersson  <mikpelinux@gmail.com>
> > 
> > 	PR target/82420
> > 	* gcc.target/m68k/pr82420.c: New test.
> This really needs to happen in the two call paths which pass in 
> NULL_TREE for the type.  Note how the type is used to determine padding 
> earlier in emit_push_insn.  That would also make the code more 
> consistent with the comment before emit_push_insn which implies that 
> both MODE and TYPE are valid.
> 
> 
> Additionally you should bootstrap and regression test this patch on at 
> least one target.

Updated as requested, and bootstrapped and tested on
{x86_64,aarch64,m68k}-linux-gnu without regressions.

gcc/

2024-01-16  Thorsten Otto  <admin@tho-otto.de>
            Mikael Pettersson  <mikpelinux@gmail.com>

	PR target/82420
	PR target/111279
	* calls.cc (emit_library_call_value_1): Pass valid TYPE
	to emit_push_insn.
	* expr.cc (emit_push_insn): Likewise.

gcc/teststuite/

2024-01-16  Mikael Pettersson  <mikpelinux@gmail.com>

	PR target/82420
	* gcc.target/m68k/pr82420.c: New test.
---
 gcc/calls.cc                            | 4 ++--
 gcc/expr.cc                             | 5 +++--
 gcc/testsuite/gcc.target/m68k/pr82420.c | 9 +++++++++
 3 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/m68k/pr82420.c

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 7c35b1ad204..01f44734743 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -4580,8 +4580,8 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
 		}
 	    }
 
-	  emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
-			  partial, reg, 0, argblock,
+	  emit_push_insn (val, mode, lang_hooks.types.type_for_mode (mode, 0),
+			  NULL_RTX, parm_align, partial, reg, 0, argblock,
 			  (gen_int_mode
 			   (argvec[argnum].locate.offset.constant, Pmode)),
 			  reg_parm_stack_space,
diff --git a/gcc/expr.cc b/gcc/expr.cc
index 34f5ff90a9f..3015f9e51d8 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -5532,11 +5532,12 @@ emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
       /* Loop over all the words allocated on the stack for this arg.  */
       /* We can do it by words, because any scalar bigger than a word
 	 has a size a multiple of a word.  */
+      tree word_mode_type = lang_hooks.types.type_for_mode (word_mode, 1);
       for (i = num_words - 1; i >= not_stack; i--)
 	if (i >= not_stack + offset)
 	  if (!emit_push_insn (operand_subword_force (x, i, mode),
-			  word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
-			  0, args_addr,
+			  word_mode, word_mode_type, NULL_RTX, align, 0,
+			  NULL_RTX, 0, args_addr,
 			  GEN_INT (args_offset + ((i - not_stack + skip)
 						  * UNITS_PER_WORD)),
 			  reg_parm_stack_space, alignment_pad, sibcall_p))
diff --git a/gcc/testsuite/gcc.target/m68k/pr82420.c b/gcc/testsuite/gcc.target/m68k/pr82420.c
new file mode 100644
index 00000000000..5c84f292103
--- /dev/null
+++ b/gcc/testsuite/gcc.target/m68k/pr82420.c
@@ -0,0 +1,9 @@
+/* { do-do compile } */
+/* { dg-options "-march=68000 -malign-int" } */
+
+int a;
+
+void f(void)
+{
+    a /= 3;
+}
  
Jeff Law Jan. 21, 2024, 11 p.m. UTC | #4
On 1/16/24 09:55, Mikael Pettersson wrote:
> On Thu, 4 Jan 2024 14:39:23 -0700, Jeff Law wrote:
>> On 1/4/24 02:23, Mikael Pettersson wrote:
>>> emit_library_call_value_1 calls emit_push_insn with NULL_TREE
>>> for TYPE.  Sometimes emit_push_insn needs to assign a temp with
>>> that TYPE, which causes a segfault.
>>>
>>> Fixed by computing the TYPE from MODE when needed.
>>>
>>> Original patch by Thorsten Otto.
>>>
>>> gcc/
>>>
>>> 2024-01-03  Thorsten Otto  <admin@tho-otto.de>
>>>               Mikael Pettersson  <mikpelinux@gmail.com>
>>>
>>> 	PR target/82420
>>> 	PR target/111279
>>> 	* expr.cc (emit_push_insn): If TYPE is NULL compute it
>>> 	from MODE before calling assign_temp.
>>>
>>> gcc/teststuite/
>>>
>>> 2024-01-03  Mikael Pettersson  <mikpelinux@gmail.com>
>>>
>>> 	PR target/82420
>>> 	* gcc.target/m68k/pr82420.c: New test.
>> This really needs to happen in the two call paths which pass in
>> NULL_TREE for the type.  Note how the type is used to determine padding
>> earlier in emit_push_insn.  That would also make the code more
>> consistent with the comment before emit_push_insn which implies that
>> both MODE and TYPE are valid.
>>
>>
>> Additionally you should bootstrap and regression test this patch on at
>> least one target.
> 
> Updated as requested, and bootstrapped and tested on
> {x86_64,aarch64,m68k}-linux-gnu without regressions.
> 
> gcc/
> 
> 2024-01-16  Thorsten Otto  <admin@tho-otto.de>
>              Mikael Pettersson  <mikpelinux@gmail.com>
> 
> 	PR target/82420
> 	PR target/111279
> 	* calls.cc (emit_library_call_value_1): Pass valid TYPE
> 	to emit_push_insn.
> 	* expr.cc (emit_push_insn): Likewise.
> 
> gcc/teststuite/
> 
> 2024-01-16  Mikael Pettersson  <mikpelinux@gmail.com>
> 
> 	PR target/82420
> 	* gcc.target/m68k/pr82420.c: New test.
I made minor adjustments to the commit message and pushed this to the trunk.

jeff
  

Patch

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 9fef2bf6585..7ab80ef176c 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -5304,7 +5304,11 @@  emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
 	  size = gen_int_mode (GET_MODE_SIZE (mode), Pmode);
 	  if (!MEM_P (xinner))
 	    {
-	      temp = assign_temp (type, 1, 1);
+	      tree atype = type;
+
+	      if (atype == NULL_TREE)
+		atype = lang_hooks.types.type_for_mode (mode, 0);
+	      temp = assign_temp (atype, 1, 1);
 	      emit_move_insn (temp, xinner);
 	      xinner = temp;
 	    }
diff --git a/gcc/testsuite/gcc.target/m68k/pr82420.c b/gcc/testsuite/gcc.target/m68k/pr82420.c
new file mode 100644
index 00000000000..5c84f292103
--- /dev/null
+++ b/gcc/testsuite/gcc.target/m68k/pr82420.c
@@ -0,0 +1,9 @@ 
+/* { do-do compile } */
+/* { dg-options "-march=68000 -malign-int" } */
+
+int a;
+
+void f(void)
+{
+    a /= 3;
+}