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] Fix the gcc.dg/builtin-return-1.c failure.


Hi,

Attached is a patch to fix

  FAIL: gcc.dg/builtin-return-1.c execution test

on m68k-elf.

The guts of this testcase is:

int bar(int n)
{
  __builtin_return(__builtin_apply((void (*)(void))foo, __builtin_apply_args(), 64));
}

Here is the stack frame right after "calling" __builtin_apply.  (I
really mean "calling" only.  I do not mean "returning from".)

+------+-----------------------------------------+
| size | purpose                                 |
+------+-----------------------------------------+
|    4 | integer 1, the argument to bar          | up
|    4 | return address                          |
|    4 | old fp                                  |
|   24 | bar's frame                             |
|   68 | work area allocated by __builtin__apply | down
+------+-----------------------------------------+

Note that __builtin_apply allocates 64 bytes in the stack, which is a
part of the 68-byte area, copies bar's arguments to the newly
allocated area, and then calls foo.  The problem is that we cannot
copy 64 bytes from the location marked as "up" above.  The "up" is so
close to the end of memory (in my setup) that we overshoot the
beginning of the stack when we attempt to copy 64 bytes.

The patch fixes this problem by guaranteeing that we have digged at
least 64 bytes by the time we reach bar.

In general, it's not a good idea to change a testcase, but in this
case it should be clear that I am not changing what the testcase is
intented to do.

Tested on m68k-elf.  OK to apply?

Kazu Hirata

2007-06-01  Kazu Hirata  <kazu@codesourcery.com>

	* gcc.dg/builtin-return-1.c (g): New.
	(main): Allocate at least 64 bytes on the stack.

Index: gcc/testsuite/gcc.dg/builtin-return-1.c
===================================================================
--- gcc/testsuite/gcc.dg/builtin-return-1.c	(revision 172754)
+++ gcc/testsuite/gcc.dg/builtin-return-1.c	(working copy)
@@ -17,8 +17,16 @@ int bar(int n)
   __builtin_return(__builtin_apply((void (*)(void))foo, __builtin_apply_args(), 64));
 }
 
+char *g;
+
 int main(void)
 {
+  /* Allocate 64 bytes on the stack to make sure that __builtin_apply
+     can read at least 64 bytes above the return address.  */
+  char dummy[64];
+
+  g = dummy;
+
   if (bar(1) != 2)
     abort();
 


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