PATCH: PR target/37843:[4.4 Regression] unaligned stack in maindue to tail call optimization

Ye, Joey joey.ye@intel.com
Thu Oct 16 07:51:00 GMT 2008


HJ worte:
> 
> Hi,
> 
> Where there is a tail call in a leaf function, we fail to align the
stack
> since we check max_used_stack_slot_alignment for stack requirement.
For
> tail call, we should check stack_alignment_needed. This patch is
tested
> on Linux/ia32.  OK for trunk?
HJ, your patch doesn't work for following test case with following
option:
-m32 -O2 -mpreferred-stack-boundary=5

Attached a patch to solve this problem by disabling sibcall in some
occasion.

#include <stdio.h>
extern void abort();
int g;
void __attribute__((noinline)) check(void * addr, int align)
{
  printf("addr = %p, align = %d\n", addr, align);
  if (((unsigned long)addr & (align -1)) != 0) abort();
}

int __attribute__((noinline)) bar()
{
  volatile int __attribute((aligned(32))) a = 0;
  check((void*)&a, __alignof__(a));
  a = g;
  return a;
}
int __attribute__((noinline)) foo()
{
int r;
  r=bar();
  return r;
}
int main()
{
  return foo();
}

ChangeLog:
2008-10-16  Joey Ye  <joey.ye@intel.com>

	PR target/37843
	* config/i386/i386.c (IS_MAIN_FUNC): Macro to
	check if a function is main.
	* (ix86_function_ok_for_sibcall): Disable sibcall
	when function call boundary needed to be realigned
	* (ix86_update_stack_boundary): Use macro
	IS_MAIN_FUNC.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sibcall_align-1014.patch
Type: application/octet-stream
Size: 1965 bytes
Desc: sibcall_align-1014.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20081016/cd3fdd4c/attachment.obj>


More information about the Gcc-patches mailing list