Fix assertion checking failure with tail call
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 17 Sep 2020 10:58:02 +0000 (12:58 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 17 Sep 2020 11:00:24 +0000 (13:00 +0200)
gcc/ChangeLog:
PR middle-end/97078
* function.c (use_register_for_decl): Test cfun->tail_call_marked
for a parameter here instead of...
(assign_parm_setup_reg): ...here.

gcc/testsuite/ChangeLog:
* gcc.dg/pr97078.c: New test.

gcc/function.c
gcc/testsuite/gcc.dg/pr97078.c [new file with mode: 0644]

index c4c9930d7251a4578e3508175569e86a0f7cf36d..c6129593b9bdaa862ac4f1a5c70e964572bcb75c 100644 (file)
@@ -2237,6 +2237,11 @@ use_register_for_decl (const_tree decl)
   if (optimize)
     return true;
 
+  /* Thunks force a tail call even at -O0 so we need to avoid creating a
+     dangling reference in case the parameter is passed by reference.  */
+  if (TREE_CODE (decl) == PARM_DECL && cfun->tail_call_marked)
+    return true;
+
   if (!DECL_REGISTER (decl))
     return false;
 
@@ -3328,9 +3333,8 @@ assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
      of the parameter instead.  */
   if (data->arg.pass_by_reference && TYPE_MODE (TREE_TYPE (parm)) != BLKmode)
     {
-      /* Use a stack slot for debugging purposes, except if a tail call is
-        involved because this would create a dangling reference.  */
-      if (use_register_for_decl (parm) || cfun->tail_call_marked)
+      /* Use a stack slot for debugging purposes if possible.  */
+      if (use_register_for_decl (parm))
        {
          parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
          mark_user_reg (parmreg);
diff --git a/gcc/testsuite/gcc.dg/pr97078.c b/gcc/testsuite/gcc.dg/pr97078.c
new file mode 100644 (file)
index 0000000..997d5fb
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffloat-store" } */
+
+extern void foo (long double);
+
+void bar (long double d)
+{
+  foo (d);
+}