Fix PR middle-end/98082
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 3 Dec 2020 14:52:15 +0000 (15:52 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 3 Dec 2020 14:56:33 +0000 (15:56 +0100)
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
gcc/testsuite/g++.dg/cpp2a/pr98082.C [new file with mode: 0644]

index 59fd72b0e820de69625fd493726bb9542ac100a0..af9618e18dff567ff96c68020152d3ebd624b2da 100644 (file)
@@ -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 (file)
index 0000000..b2caacb
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR middle-end/98082 */
+/* Reported by Martin Liska <marxin@gcc.gnu.org> */
+
+/* { 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(); }