summaryrefslogtreecommitdiff
path: root/lib/alloca.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-06-20 15:03:03 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-06-20 15:14:59 -0700
commitc3dbfe95b16dfd35bba520c1d90275e9622e1a46 (patch)
treed04f04fe4685cb1af2f7a9eface0518441fe4033 /lib/alloca.c
parent3c4ad6125cf33faf3cc090b4232d35f3866b9799 (diff)
downloadgnulib-c3dbfe95b16dfd35bba520c1d90275e9622e1a46.tar.gz
alloca: port to compilers that can optimize like GCC 4.6.0
* lib/alloca.c (find_stack_direction): New signature, taken from Autoconf git. This works with GCC 4.6.0. This code should never be used with GCC 4.6.0 itself, as GCC has alloca, but it might be used with other compilers that optimize as well as GCC 4.6.0 does. (alloca): Adjust to new signature. * m4/alloca.m4 (__AC_LIBOBJ_ALLOCA) [Autoconf version < 2.69]: New macro, which patches Autoconf in a similar way.
Diffstat (limited to 'lib/alloca.c')
-rw-r--r--lib/alloca.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/alloca.c b/lib/alloca.c
index 2f5e27ec69..c7e91ab933 100644
--- a/lib/alloca.c
+++ b/lib/alloca.c
@@ -93,25 +93,15 @@ long i00afunc ();
static int stack_dir; /* 1 or -1 once known. */
# define STACK_DIR stack_dir
-static void
-find_stack_direction (char **ptr)
+static int
+find_stack_direction (int *addr, int depth)
{
- auto char dummy; /* To get stack address. */
-
- if (*ptr == NULL)
- { /* Initial entry. */
- *ptr = ADDRESS_FUNCTION (dummy);
-
- find_stack_direction (ptr); /* Recurse once. */
- }
- else
- {
- /* Second entry. */
- if (ADDRESS_FUNCTION (dummy) > *ptr)
- stack_dir = 1; /* Stack grew upward. */
- else
- stack_dir = -1; /* Stack grew downward. */
- }
+ int dir, dummy = 0;
+ if (! addr)
+ addr = &dummy;
+ *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
+ dir = depth ? find_stack_direction (addr, depth - 1) : 0;
+ return dir + dummy;
}
# endif /* STACK_DIRECTION == 0 */
@@ -154,10 +144,7 @@ alloca (size_t size)
# if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
- {
- char *addr = NULL; /* Address of first `dummy', once known. */
- find_stack_direction (&addr);
- }
+ STACK_DIR = find_stack_direction (NULL, (size & 1) + 20);
# endif
/* Reclaim garbage, defined as all alloca'd storage that