bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] vararrays: modernize AC_C_VARARRAYS for C11


From: Paul Eggert
Subject: [PATCH] vararrays: modernize AC_C_VARARRAYS for C11
Date: Thu, 7 Aug 2014 17:26:47 -0700

This backports a change I recently made to Autoconf.
* m4/vararrays.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.
---
 ChangeLog       |  9 +++++++++
 m4/vararrays.m4 | 59 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e8dd13e..386520b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-08-07  Paul Eggert  <address@hidden>
+
+       vararrays: modernize AC_C_VARARRAYS for C11
+       This backports a change I recently made to Autoconf.
+       * m4/vararrays.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.
+
 2014-08-07  Alessandro Degano  <address@hidden>  (tiny change)
 
        relocatable-prog-wrapper: port gettext to OS X 10.8 + GCC 4.8.1
diff --git a/m4/vararrays.m4 b/m4/vararrays.m4
index 9d59709..cbda525 100644
--- a/m4/vararrays.m4
+++ b/m4/vararrays.m4
@@ -1,6 +1,6 @@
 # Check for variable-length arrays.
 
-# serial 4
+# serial 5
 
 # From Paul Eggert
 
@@ -9,17 +9,60 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# This is a copy of AC_C_VARARRAYS from a recent development version
+# of Autoconf.  It replaces Autoconf's version, or for pre-2.61 autoconf
+# it defines the macro that Autoconf lacks.
 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_DEFINE([HAVE_C_VARARRAYS], [1],
+    [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]