Mercurial > hg > octave-shane > gnulib-hg
annotate m4/alloca.m4 @ 15304:578f64214a48
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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 20 Jun 2011 15:03:03 -0700 |
parents | 662ae53d8d37 |
children | 03e2cd1cbbe8 |
rev | line source |
---|---|
15304
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
1 # alloca.m4 serial 12 |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
13870
diff
changeset
|
2 dnl Copyright (C) 2002-2004, 2006-2007, 2009-2011 Free Software Foundation, |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
11007
diff
changeset
|
3 dnl Inc. |
5611
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5063
diff
changeset
|
4 dnl This file is free software; the Free Software Foundation |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5063
diff
changeset
|
5 dnl gives unlimited permission to copy and/or distribute it, |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5063
diff
changeset
|
6 dnl with or without modifications, as long as this notice is preserved. |
4107
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 AC_DEFUN([gl_FUNC_ALLOCA], |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 [ |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 AC_REQUIRE([AC_FUNC_ALLOCA]) |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 if test $ac_cv_func_alloca_works = no; then |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 gl_PREREQ_ALLOCA |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 fi |
4156
99ea86c79f44
Make it possibly to simply write: #include <alloca.h>.
Bruno Haible <bruno@clisp.org>
parents:
4107
diff
changeset
|
14 |
99ea86c79f44
Make it possibly to simply write: #include <alloca.h>.
Bruno Haible <bruno@clisp.org>
parents:
4107
diff
changeset
|
15 # Define an additional variable used in the Makefile substitution. |
5063
1aecdc8063ba
alloca cleanup: always include <alloca.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4631
diff
changeset
|
16 if test $ac_cv_working_alloca_h = yes; then |
7662 | 17 AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [ |
7535 | 18 AC_EGREP_CPP([Need own alloca], [ |
5063
1aecdc8063ba
alloca cleanup: always include <alloca.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4631
diff
changeset
|
19 #if defined __GNUC__ || defined _AIX || defined _MSC_VER |
7662 | 20 Need own alloca |
4156
99ea86c79f44
Make it possibly to simply write: #include <alloca.h>.
Bruno Haible <bruno@clisp.org>
parents:
4107
diff
changeset
|
21 #endif |
7662 | 22 ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no]) |
7535 | 23 ]) |
24 if test $gl_cv_rpl_alloca = yes; then | |
7662 | 25 dnl OK, alloca can be implemented through a compiler built-in. |
11007
f6cba5a556ce
many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents:
9592
diff
changeset
|
26 AC_DEFINE([HAVE_ALLOCA], [1], |
7662 | 27 [Define to 1 if you have 'alloca' after including <alloca.h>, |
28 a header that may be supplied by this distribution.]) | |
7535 | 29 ALLOCA_H=alloca.h |
30 else | |
7662 | 31 dnl alloca exists as a library function, i.e. it is slow and probably |
32 dnl a memory leak. Don't define HAVE_ALLOCA in this case. | |
7535 | 33 ALLOCA_H= |
34 fi | |
5063
1aecdc8063ba
alloca cleanup: always include <alloca.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4631
diff
changeset
|
35 else |
1aecdc8063ba
alloca cleanup: always include <alloca.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4631
diff
changeset
|
36 ALLOCA_H=alloca.h |
1aecdc8063ba
alloca cleanup: always include <alloca.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4631
diff
changeset
|
37 fi |
4156
99ea86c79f44
Make it possibly to simply write: #include <alloca.h>.
Bruno Haible <bruno@clisp.org>
parents:
4107
diff
changeset
|
38 AC_SUBST([ALLOCA_H]) |
14528
662ae53d8d37
Remove leftover generated .h files after config.status changed.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
39 AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"]) |
4107
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 ]) |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 # Prerequisites of lib/alloca.c. |
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 # STACK_DIRECTION is already handled by AC_FUNC_ALLOCA. |
4631 | 44 AC_DEFUN([gl_PREREQ_ALLOCA], [:]) |
15304
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
45 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
46 # This works around a bug in autoconf <= 2.68. |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
47 # See <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00277.html>. |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
48 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
49 m4_version_prereq([2.69], [] ,[ |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
50 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
51 # This is taken from the following Autoconf patch: |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
52 # http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
53 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
54 # _AC_LIBOBJ_ALLOCA |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
55 # ----------------- |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
56 # Set up the LIBOBJ replacement of `alloca'. Well, not exactly |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
57 # AC_LIBOBJ since we actually set the output variable `ALLOCA'. |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
58 # Nevertheless, for Automake, AC_LIBSOURCES it. |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
59 m4_define([_AC_LIBOBJ_ALLOCA], |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
60 [# The SVR3 libPW and SVR4 libucb both contain incompatible functions |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
61 # that cause trouble. Some versions do not even contain alloca or |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
62 # contain a buggy version. If you still want to use their alloca, |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
63 # use ar to extract alloca.o from them instead of compiling alloca.c. |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
64 AC_LIBSOURCES(alloca.c) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
65 AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
66 AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using `alloca.c'.]) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
67 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
68 AC_CACHE_CHECK(whether `alloca.c' needs Cray hooks, ac_cv_os_cray, |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
69 [AC_EGREP_CPP(webecray, |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
70 [#if defined CRAY && ! defined CRAY2 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
71 webecray |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
72 #else |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
73 wenotbecray |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
74 #endif |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
75 ], ac_cv_os_cray=yes, ac_cv_os_cray=no)]) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
76 if test $ac_cv_os_cray = yes; then |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
77 for ac_func in _getb67 GETB67 getb67; do |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
78 AC_CHECK_FUNC($ac_func, |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
79 [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
80 [Define to one of `_getb67', `GETB67', |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
81 `getb67' for Cray-2 and Cray-YMP |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
82 systems. This function is required for |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
83 `alloca.c' support on those systems.]) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
84 break]) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
85 done |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
86 fi |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
87 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
88 AC_CACHE_CHECK([stack direction for C alloca], |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
89 [ac_cv_c_stack_direction], |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
90 [AC_RUN_IFELSE([AC_LANG_SOURCE( |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
91 [AC_INCLUDES_DEFAULT |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
92 int |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
93 find_stack_direction (int *addr, int depth) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
94 { |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
95 int dir, dummy = 0; |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
96 if (! addr) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
97 addr = &dummy; |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
98 *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
99 dir = depth ? find_stack_direction (addr, depth - 1) : 0; |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
100 return dir + dummy; |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
101 } |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
102 |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
103 int |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
104 main (int argc, char **argv) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
105 { |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
106 return find_stack_direction (0, argc + !argv + 20) < 0; |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
107 }])], |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
108 [ac_cv_c_stack_direction=1], |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
109 [ac_cv_c_stack_direction=-1], |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
110 [ac_cv_c_stack_direction=0])]) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
111 AH_VERBATIM([STACK_DIRECTION], |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
112 [/* If using the C implementation of alloca, define if you know the |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
113 direction of stack growth for your system; otherwise it will be |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
114 automatically deduced at runtime. |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
115 STACK_DIRECTION > 0 => grows toward higher addresses |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
116 STACK_DIRECTION < 0 => grows toward lower addresses |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
117 STACK_DIRECTION = 0 => direction of growth unknown */ |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
118 @%:@undef STACK_DIRECTION])dnl |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
119 AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction) |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
120 ])# _AC_LIBOBJ_ALLOCA |
578f64214a48
alloca: port to compilers that can optimize like GCC 4.6.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
14528
diff
changeset
|
121 ]) |