view m4/vararrays.m4 @ 40214:452ab00796c7

Fix undefined behaviour. * lib/bitrotate.h (rotl16, rotr16, rotl8, rotr8): Case x to 'unsigned int', to avoid shift operations on 'int'. * lib/xmemdup0.c (xmemdup0): Don't invoke memcpy with a zero size. * tests/test-count-leading-zeros.c (main): Use a random number that has as many bits as TYPE, not only 2*15 or 2*31 bits. * tests/test-count-trailing-zeros.c (main): Likewise. * tests/test-count-one-bits.c (main): Likewise. * tests/test-memmem.c: Don't include "null-ptr.h". (main): Use zerosize_ptr() instead of null_ptr(). * modules/memmem-tests (Files): Remove tests/null-ptr.h.
author Bruno Haible <bruno@clisp.org>
date Sat, 09 Mar 2019 20:32:25 +0100
parents b06060465f09
children
line wrap: on
line source

# Check for variable-length arrays.

# serial 5

# From Paul Eggert

# Copyright (C) 2001, 2009-2019 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# 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_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:
                  https://lists.gnu.org/r/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
])