From: Paul Eggert Date: Fri, 8 Aug 2014 00:25:28 +0000 (-0700) Subject: vararrays: modernize AC_C_VARARRAYS for C11 X-Git-Tag: v1.0~7319 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e8e10012c00e6e92496f11289a6e1ffc5503db77;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index e8dd13e278..386520bf83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2014-08-07 Paul Eggert + + 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 (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 9d597094d2..cbda525c75 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 ])