Mercurial > gnulib
annotate m4/stdalign.m4 @ 16318:39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
* m4/stdalign.m4 (gl_STDALIGN_H): Check for GCC bug 52023.
Problem reported for gnulib by Richard W.M. Jones in
<http://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00340.html>.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 27 Jan 2012 10:17:18 -0800 |
parents | 91f53c1e1787 |
children | 934a441c5452 |
rev | line source |
---|---|
16239
91f53c1e1787
doc: C11 and C++11 are now official
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
1 # Check for stdalign.h that conforms to C11. |
15994 | 2 |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
16140
diff
changeset
|
3 dnl Copyright 2011-2012 Free Software Foundation, Inc. |
15994 | 4 dnl This file is free software; the Free Software Foundation |
5 dnl gives unlimited permission to copy and/or distribute it, | |
6 dnl with or without modifications, as long as this notice is preserved. | |
7 | |
8 # Prepare for substituting <stdalign.h> if it is not supported. | |
9 | |
10 AC_DEFUN([gl_STDALIGN_H], | |
11 [ | |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
12 AC_CACHE_CHECK([for working stdalign.h], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
13 [gl_cv_header_working_stdalign_h], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
14 [AC_COMPILE_IFELSE( |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
15 [AC_LANG_PROGRAM( |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
16 [[#include <stdalign.h> |
16318
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
17 #include <stddef.h> |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
18 |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
19 /* Test that alignof yields a result consistent with offsetof. |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
20 This catches GCC bug 51316 |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
21 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51316>. */ |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
22 #ifdef __cplusplus |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
23 template <class t> struct alignof_helper { char a; t b; }; |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
24 # define ao(type) offsetof (alignof_helper<type>, b) |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
25 #else |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
26 # define ao(type) offsetof (struct { char a; type b; }, b) |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
27 #endif |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
28 char test1[_Alignof (double) == ao (double) ? 1 : -1]; |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
29 char test2[alignof (long int) == ao (long int) ? 1 : -1]; |
15994 | 30 |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
31 /* Test _Alignas only on platforms where gnulib can help. */ |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
32 #if \ |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
33 (__GNUC__ || __IBMC__ || __IBMCPP__ \ |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
34 || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER) |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
35 int alignas (8) alignas_int = 1; |
16318
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
36 char test3[8 <= _Alignof (alignas_int) ? 1 : -1]; |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
37 #endif |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
38 ]])], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
39 [gl_cv_header_working_stdalign_h=yes], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
40 [gl_cv_header_working_stdalign_h=no])]) |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
41 |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
42 if test $gl_cv_header_working_stdalign_h = yes; then |
15994 | 43 STDALIGN_H='' |
44 else | |
45 STDALIGN_H='stdalign.h' | |
46 fi | |
47 | |
48 AC_SUBST([STDALIGN_H]) | |
49 AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"]) | |
50 ]) |