PR c++/84964: Middle-end patch to expand_call for ICE after sorry.

Message ID 000901d82c78$33860b30$9a922190$@nextmovesoftware.com
State New
Headers
Series PR c++/84964: Middle-end patch to expand_call for ICE after sorry. |

Commit Message

Roger Sayle Feb. 28, 2022, 7:52 a.m. UTC
  This patch resolves PR c++/84964 which is an ICE in the middle-end after
emitting a "sorry, unimplemented" message, and is a regression from
earlier releases of GCC.  This issue is that after encountering a
function call requiring an unreasonable amount of stack space, the
code continues and falls foul of an assert checking that stack pointer
has been correctly updated.  The fix is to (locally) consider aborted
function calls as "no return", which skips this downstream sanity check.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check with no new failures.  Ok for mainline?


2022-02-28  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	PR c++/84964
	* calls.cc (expand_call): Ignore stack adjustments after sorry.

gcc/testsuite/ChangeLog
	PR c++/84964
	* g++.dg/pr84964.C: New test case.


Thanks in advance,
Roger
--
  

Comments

Jason Merrill March 10, 2022, 2:15 p.m. UTC | #1
On 2/28/22 03:52, Roger Sayle wrote:
> 
> This patch resolves PR c++/84964 which is an ICE in the middle-end after
> emitting a "sorry, unimplemented" message, and is a regression from
> earlier releases of GCC.  This issue is that after encountering a
> function call requiring an unreasonable amount of stack space, the
> code continues and falls foul of an assert checking that stack pointer
> has been correctly updated.  The fix is to (locally) consider aborted
> function calls as "no return", which skips this downstream sanity check.
> 
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check with no new failures.  Ok for mainline?
> 
> 
> 2022-02-28  Roger Sayle  <roger@nextmovesoftware.com>
> 
> gcc/ChangeLog
> 	PR c++/84964
> 	* calls.cc (expand_call): Ignore stack adjustments after sorry.
> 
> gcc/testsuite/ChangeLog
> 	PR c++/84964
> 	* g++.dg/pr84964.C: New test case.

Again I'd prefer to have the test in a subdirectory, though which one is 
less clear; either opt or other, I guess.  OK with that change.
  

Patch

diff --git a/gcc/calls.cc b/gcc/calls.cc
index e64a937..d4ee015 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -3447,6 +3447,8 @@  expand_call (tree exp, rtx target, int ignore)
 		  >= (1 << (HOST_BITS_PER_INT - 2)))
 	        {
 	          sorry ("passing too large argument on stack");
+		  /* Don't worry about stack clean-up.  */
+		  flags |= ECF_NORETURN;
 		  continue;
 		}
 
diff --git a/gcc/testsuite/g++.dg/pr84964.C b/gcc/testsuite/g++.dg/pr84964.C
new file mode 100644
index 0000000..1d0ff20
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr84964.C
@@ -0,0 +1,8 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+struct a {
+  short b : -1ULL;  // { dg-warning "exceeds its type" }
+};
+void c(...) { c(a()); }  // { dg-message "sorry, unimplemented" }
+