This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: Restore stack pointer properly when function calls alloca


This change

2004-09-08 Richard Henderson <rth@redhat.com>

        PR rtl-opt/17186
        * function.c (expand_function_end): Have fall-off-the-end
        return path jump around return register setup.

introduced a problem for ports where EXIT_IGNORE_STACK == 0, such as the Blackfin port which I'm working on. If current_function_calls_alloca, we emit code to save and restore the stack pointer, but the change above emits a jump around the restore insn, which promptly gets deleted as dead.

I've checked in the following patch. Bootstrapped on i686-linux (not very useful since EXIT_IGNORE_STACK == 1), and regression tested on mcore-elf, where it fixes a few failures:

-FAIL: gcc.c-torture/execute/941202-1.c execution,  -O1
-FAIL: gcc.c-torture/execute/941202-1.c execution,  -O2
-FAIL: gcc.c-torture/execute/941202-1.c execution,  -O3 -fomit-frame-pointer
-FAIL: gcc.c-torture/execute/941202-1.c execution,  -O3 -g
-FAIL: gcc.c-torture/execute/941202-1.c execution,  -Os

This is the same testcase that was failing with the Blackfin port.


Bernd
	* function.c (expand_function_end): If current_function_calls_alloca,
	emit stack restore in a place that is reached when the function falls
	through at the end.

Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.603
diff -c -p -r1.603 function.c
*** function.c	23 Jan 2005 08:27:47 -0000	1.603
--- function.c	26 Jan 2005 11:19:29 -0000
*************** expand_function_end (void)
*** 4460,4477 ****
    if (flag_exceptions && USING_SJLJ_EXCEPTIONS)
      sjlj_emit_function_exit_after (get_last_insn ());
  
-   /* If we had calls to alloca, and this machine needs
-      an accurate stack pointer to exit the function,
-      insert some code to save and restore the stack pointer.  */
-   if (! EXIT_IGNORE_STACK
-       && current_function_calls_alloca)
-     {
-       rtx tem = 0;
- 
-       emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
-       emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
-     }
- 
    /* If scalar return value was computed in a pseudo-reg, or was a named
       return value that got dumped to the stack, copy that to the hard
       return register.  */
--- 4460,4465 ----
*************** expand_function_end (void)
*** 4599,4604 ****
--- 4587,4604 ----
    /* Output the label for the naked return from the function.  */
    emit_label (naked_return_label);
  
+   /* If we had calls to alloca, and this machine needs
+      an accurate stack pointer to exit the function,
+      insert some code to save and restore the stack pointer.  */
+   if (! EXIT_IGNORE_STACK
+       && current_function_calls_alloca)
+     {
+       rtx tem = 0;
+ 
+       emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
+       emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
+     }
+ 
    /* ??? This should no longer be necessary since stupid is no longer with
       us, but there are some parts of the compiler (eg reload_combine, and
       sh mach_dep_reorg) that still try and compute their own lifetime info

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]