autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] autoconf: modernize AC_C_VARARRAYS for C11


From: Paul Eggert
Subject: [PATCH 3/3] autoconf: modernize AC_C_VARARRAYS for C11
Date: Thu, 7 Aug 2014 17:18:22 -0700

* lib/autoconf/c.m4 (AC_C_VARARRAYS): Define __STDC_NO_VLA__ if
VLAs are not supported, as this is what C11 does.  The old macro
HAVE_C_VARARRAYS is still defined if they are supported, but is
now obsolescent.  Also, check for VLA bug in GCC 3.4.3.
* doc/autoconf.texi (C Compiler), NEWS: Document the above.
---
 NEWS              |  6 ++++++
 doc/autoconf.texi | 12 ++++++++----
 lib/autoconf/c.m4 | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index 3f66825..6e2aabd 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,12 @@ GNU Autoconf NEWS - User visible changes.
 
 - New macro AC_C__GENERIC.
 
+- AC_C_VARARRAYS now defines __STDC_NO_VLA__ if variable-length
+  arrays are not supported and if the compiler does not already
+  define __STDC_NO_VLA__.  This is for compatibility with C11.
+  For backward compatibility with Autoconf 2.61-2.69 AC_C_VARARRAYS
+  still defines HAVE_C_VARARRAYS, but this usage is obsolescent.
+
 - AC_CONFIG_MACRO_DIRS
   New macro, used to declare multiple directories when looking for
   local M4 macros.  This macro overcomes some of the shortfalls in the
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 791436b..83e6643 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7488,11 +7488,15 @@ for (i = 0; i < n; i++)
 
 @defmac AC_C_VARARRAYS
 @acindex{C_VARARRAYS}
address@hidden __STDC_NO_VLA__
 @cvindex HAVE_C_VARARRAYS
-If the C compiler supports variable-length arrays, define
address@hidden  A variable-length array is an array of automatic
-storage duration whose length is determined at run time, when the array
-is declared.
+If the C compiler does not support variable-length arrays, define the
+macro @code{__STDC_NO_VLA__} to be 1 if it is not already defined.  A
+variable-length array is an array of automatic storage duration whose
+length is determined at run time, when the array is declared.  For
+backward compatibility this macro also defines @code{HAVE_C_VARARRAYS}
+if the C compiler supports variable-length arrays, but this usage is
+obsolescent and new programs should use @code{__STDC_NO_VLA__}.
 @end defmac
 
 @defmac AC_C_TYPEOF
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index b58e42d..a944529 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1995,14 +1995,54 @@ AC_DEFUN([AC_C_VARARRAYS],
 [
   AC_CACHE_CHECK([for variable-length arrays],
     ac_cv_c_vararrays,
-    [AC_COMPILE_IFELSE(
-       [AC_LANG_PROGRAM([],
-         [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
-       [ac_cv_c_vararrays=yes],
-       [ac_cv_c_vararrays=no])])
-  if test $ac_cv_c_vararrays = yes; then
+    [AC_EGREP_CPP([defined],
+       [#ifdef __STDC_NO_VLA__
+       defined
+       #endif
+       ],
+       [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
+       [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[/* Test for VLA support.  This test is partly inspired
+                 from examples in the C standard.  Use at least two VLA
+                 functions to detect the GCC 3.4.3 bug described in:
+                 
http://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
+                 */
+              #ifdef __STDC_NO_VLA__
+               syntax error;
+              #else
+                extern int n;
+                int B[100];
+                int fvla (int m, int C[m][m]);
+
+                int
+                simple (int count, int all[static count])
+                {
+                  return all[count - 1];
+                }
+
+                int
+                fvla (int m, int C[m][m])
+                {
+                  typedef int VLA[m][m];
+                  VLA x;
+                  int D[m];
+                  static int (*q)[m] = &B;
+                  int (*s)[n] = q;
+                  return C && &x[0][0] == &D[0] && &D[0] == s[0];
+                }
+              #endif
+              ]])],
+         [ac_cv_c_vararrays=yes],
+         [ac_cv_c_vararrays=no])])])
+  if test "$ac_cv_c_vararrays" = yes; then
+    dnl This is for compatibility with Autoconf 2.61-2.69.
     AC_DEFINE([HAVE_C_VARARRAYS], 1,
       [Define to 1 if C supports variable-length arrays.])
+  elif test "$ac_cv_c_vararrays" = no; then
+    AC_DEFINE([__STDC_NO_VLA__], 1,
+      [Define to 1 if C does not support variable-length arrays, and
+       if the compiler does not already define this.])
   fi
 ])
 
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]