From 5d103763b9bc6a998dd4a453861663b229d7a24a Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 3 Dec 2020 15:52:15 +0100 Subject: [PATCH] Fix PR middle-end/98082 this fixes an ICE introduced by the fix for PR middle-end/97078 where use_register_for_decl was changed to return true at -O0 for a parameter of a thunk. It turns out that we need to do the same for a result in this case. gcc/ChangeLog: PR middle-end/98082 * function.c (use_register_for_decl): Also return true for a result if cfun->tail_call_marked is true. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/pr98082.C: New test. --- gcc/function.c | 6 ++++-- gcc/testsuite/g++.dg/cpp2a/pr98082.C | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/pr98082.C diff --git a/gcc/function.c b/gcc/function.c index 59fd72b0e82..af9618e18df 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -2206,13 +2206,15 @@ use_register_for_decl (const_tree decl) /* Otherwise, if RESULT_DECL is DECL_BY_REFERENCE, it will take the function_result_decl's assignment. Since it's a pointer, we can short-circuit a number of the tests below, and we must - duplicat e them because we don't have the - function_result_decl to test. */ + duplicate them because we don't have the function_result_decl + to test. */ if (!targetm.calls.allocate_stack_slots_for_args ()) return true; /* We don't set DECL_IGNORED_P for the function_result_decl. */ if (optimize) return true; + if (cfun->tail_call_marked) + return true; /* We don't set DECL_REGISTER for the function_result_decl. */ return false; } diff --git a/gcc/testsuite/g++.dg/cpp2a/pr98082.C b/gcc/testsuite/g++.dg/cpp2a/pr98082.C new file mode 100644 index 00000000000..b2caacb55df --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/pr98082.C @@ -0,0 +1,14 @@ +/* PR middle-end/98082 */ +/* Reported by Martin Liska */ + +/* { dg-do compile { target c++20 } } */ +/* { dg-options "-fipa-icf" } */ + +class GoodIter { +public: + GoodIter(); + GoodIter(GoodIter &); +}; + +GoodIter operator-(int, GoodIter) { return GoodIter(); } +GoodIter operator+(int, GoodIter) { return GoodIter(); } -- 2.30.2