]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Add AC_CHECK_ALIGNOF.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 15 Mar 2004 22:00:05 +0000 (22:00 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 15 Mar 2004 22:00:05 +0000 (22:00 +0000)
ChangeLog
NEWS
doc/autoconf.texi
lib/autoconf/types.m4
tests/mktests.sh
tests/semantics.at

index 5c1589c116789b7d073c466ad1719c94f397be9a..3d3dcefc734ee0bfb07ca9b1ec5333c4c44574d8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-03-15  Paul Eggert  <eggert@gnu.org>
+
+       * NEWS: New macro AC_CHECK_ALIGNOF.
+       * doc/autoconf.texi (Generic Compiler Characteristics): Document it.
+       * lib/autoconf/types.m4 (AC_CHECK_SIZEOF): Use long int rather than int;
+       avoid "a `$1'" since this isn't grammatical if $1 begins with a vowel.
+       (AC_CHECK_ALIGNOF): New macro.
+       * tests/mktests.sh (ac_exclude_list): Exclude AC_CHECK_ALIGNOF.
+       * tests/semantics.at (AC_CHECK_ALIGNOF): Add tests similar to
+       those for sizeof.
+
 2004-03-03  Paul Eggert  <eggert@twinsun.com>
 
        * bin/Makefile.am (edit): Don't use $< in a context where
diff --git a/NEWS b/NEWS
index 2478bb73f5c8e909236c9ddcd50961f3865f1697..266f757a760548bf307eafe4418be0d0aa9e13ef 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+* Major changes in Autoconf 2.59b
+
+** AC_CHECK_ALIGNOF
+  New macro that computes the default alignment of a type.
+
 * Major changes in Autoconf 2.59a
 
 ** AC_PROG_GREP
@@ -1176,8 +1181,8 @@ Various bug fixes.
 
 -----
 
-Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003
-Free Software Foundation, Inc.
+Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
+2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Autoconf.
 
index 6e550241806b01e5c77eda41859be81bda31cc1e..54f32359f39c753db4d8f12d41b1e67eb792130b 100644 (file)
@@ -5310,6 +5310,16 @@ AC_CHECK_SIZEOF(int *)
 defines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.
 @end defmac
 
+@defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, default-includes})
+@acindex{CHECK_ALIGNOF}
+Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be the
+alignment in bytes of @var{type}.  If @samp{type} is unknown, it gets a size
+of 0.  If no @var{includes} are specified, the default includes are used
+(@pxref{Default Includes}).  If you provide @var{include}, be sure to
+include @file{stddef.h} and @file{stdio.h} which are required for this
+macro to work correctly.
+@end defmac
+
 @defmac AC_LANG_WERROR
 @acindex{LANG_WERROR}
 Normally Autoconf ignores warnings generated by the compiler, linker, and
index 2a847b457f54d77ef1604c0071f2b87dde5902b2..450f6e488ff421a48df21ea5b1dbafbf558968ad 100644 (file)
@@ -389,11 +389,11 @@ AC_DEFUN([AC_CHECK_SIZEOF],
 AC_CHECK_TYPE([$1], [], [], [$3])
 AC_CACHE_CHECK([size of $1], AS_TR_SH([ac_cv_sizeof_$1]),
 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
-  # The cast to unsigned long works around a bug in the HP C Compiler
+  # The cast to long int works around a bug in the HP C Compiler
   # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
   # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
   # This bug is HP SR number 8606223364.
-  _AC_COMPUTE_INT([(long) (sizeof ($1))],
+  _AC_COMPUTE_INT([(long int) (sizeof ($1))],
                  [AS_TR_SH([ac_cv_sizeof_$1])],
                  [AC_INCLUDES_DEFAULT([$3])],
                  [AC_MSG_FAILURE([cannot compute sizeof ($1), 77])])
@@ -401,14 +401,32 @@ else
   AS_TR_SH([ac_cv_sizeof_$1])=0
 fi])dnl
 AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
-                  [The size of `$1', as computed by sizeof.])
+                  [The size of `$1', as computed by sizeof.])
 ])# AC_CHECK_SIZEOF
 
 
+# AC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
+# -----------------------------------------------------
+AC_DEFUN([AC_CHECK_ALIGNOF],
+[AS_LITERAL_IF([$1], [],
+              [AC_FATAL([$0: requires literal arguments])])dnl
+AC_CHECK_TYPE([$1], [], [], [$2])
+AC_CACHE_CHECK([alignment of $1], AS_TR_SH([ac_cv_alignof_$1]),
+[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
+  _AC_COMPUTE_INT([offsetof (struct { char x; $1 y; }, y)],
+                 [AS_TR_SH([ac_cv_alignof_$1])],
+                 [AC_INCLUDES_DEFAULT([$2])
+#ifndef offsetof
+# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
+#endif],
+                 [AC_MSG_FAILURE([cannot compute alignment of ($1), 77])])
+else
+  AS_TR_SH([ac_cv_alignof_$1])=0
+fi])dnl
+AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$1), $AS_TR_SH([ac_cv_alignof_$1]),
+                  [The normal alignment of `$1', in bytes.])
+])# AC_CHECK_ALIGNOF
 
-# ---------------- #
-# Generic checks.  #
-# ---------------- #
 
 # AU::AC_INT_16_BITS
 # ------------------
index ff17f4796574d8ed7a0a29cd4d0a0dab8ce49ccb..4745aead614cdf44282c38a71abf2aeb96df2841 100755 (executable)
@@ -82,7 +82,7 @@ exclude_list='^ac_cv_prog_(gcc|gxx|g77)$
 # - AC_CANONICALIZE, AC_PREFIX_PROGRAM, AC_PREREQ
 #   Need an argument.
 #
-# - AC_CHECK decl, file, func, header, lib, member, prog, sizeof, type
+# - AC_CHECK alignof, decl, file, func, header, lib, member, prog, sizeof, type
 #   Performed in the semantics tests.
 #
 # - AC_CONFIG
@@ -131,7 +131,7 @@ exclude_list='^ac_cv_prog_(gcc|gxx|g77)$
 #
 ac_exclude_list='^AC_ARG_VAR$
 ^AC_CANONICALIZE|AC_PREFIX_PROGRAM|AC_PREREQ$
-^AC_CHECK_(DECL|FILE|FUNC|HEADER|LIB|MEMBER|PROG|SIZEOF|TOOL|TYPE)S?$
+^AC_CHECK_(ALIGNOF|DECL|FILE|FUNC|HEADER|LIB|MEMBER|PROG|SIZEOF|TOOL|TYPE)S?$
 ^AC_CONFIG
 ^AC_(F77|FC)_FUNC$
 ^AC_FC_(FUNC|FREEFORM|SRCEXT)$
index d9450e9d6716b999390a2696a14a2eca6922a797..dbff9395ffc9d6242a74daf0f76cc48527819b68 100644 (file)
@@ -2,7 +2,7 @@
 
 AT_BANNER([Semantics.])
 
-# Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -239,6 +239,43 @@ AT_CHECK_MACRO([AC_CHECK_MEMBERS],
 ])])
 
 
+# AC_CHECK_ALIGNOF
+# ----------------
+# Not cross-compiling.
+AT_CHECK_MACRO([AC_CHECK_ALIGNOF],
+[[AC_CHECK_ALIGNOF(char)
+AC_CHECK_ALIGNOF(charchar,
+[[#include <stddef.h>
+#include <stdio.h>
+typedef char charchar[2];]])
+AC_CHECK_ALIGNOF(charcharchar)
+]],
+[AT_CHECK_DEFINES(
+[#define ALIGNOF_CHAR 1
+#define ALIGNOF_CHARCHAR 1
+#define ALIGNOF_CHARCHARCHAR 0
+])])
+
+
+# AC_CHECK_ALIGNOF
+# ----------------
+AT_CHECK_MACRO([AC_CHECK_ALIGNOF],
+[[# Exercise the code used when cross-compiling
+cross_compiling=yes
+AC_CHECK_ALIGNOF(char)
+AC_CHECK_ALIGNOF(charchar,
+[[#include <stddef.h>
+#include <stdio.h>
+typedef char charchar[2];]])
+AC_CHECK_ALIGNOF(charcharchar)
+]],
+[AT_CHECK_DEFINES(
+[#define ALIGNOF_CHAR 1
+#define ALIGNOF_CHARCHAR 1
+#define ALIGNOF_CHARCHARCHAR 0
+])])
+
+
 # AC_CHECK_SIZEOF
 # ---------------
 # Not cross-compiling.