diff options
| author | Paul Eggert | 2016-09-20 08:30:17 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-09-20 08:32:15 -0700 |
| commit | d9741b61c8e446de084cc4dc609aaa8e5702118d (patch) | |
| tree | bc7dee77f208e70918e0c15aa91eb728f27b0c47 /m4 | |
| parent | 83fbb3a6dd75e01a768cb6b3348b7c947711ee46 (diff) | |
| download | emacs-d9741b61c8e446de084cc4dc609aaa8e5702118d.tar.gz emacs-d9741b61c8e446de084cc4dc609aaa8e5702118d.zip | |
Use flexmembers on IBM XL C for AIX
This removes a workaround where Emacs did not use flexible
array members when compiled with IBM XL C. Instead, avoid
the problem by making the aliasing issues more obvious to
this compiler.
* admin/merge-gnulib: Don’t remove m4/flexmember.m4.
* m4/flexmember.m4: Copy from gnulib.
* configure.ac (AC_C_FLEXIBLE_ARRAY_MEMBER): Remove workaround.
* src/alloc.c (allocate_string_data): Rephrase to avoid aliasing
problem that would otherwise mess up code generated for flexible
array members by IBM XL C for AIX, V12.1.
* src/conf_post.h (FLEXIBLE_ARRAY_MEMBER): Remove; now done
by gnulib code.
Diffstat (limited to 'm4')
| -rw-r--r-- | m4/flexmember.m4 | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/m4/flexmember.m4 b/m4/flexmember.m4 new file mode 100644 index 00000000000..155ae9b8120 --- /dev/null +++ b/m4/flexmember.m4 | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | # serial 4 | ||
| 2 | # Check for flexible array member support. | ||
| 3 | |||
| 4 | # Copyright (C) 2006, 2009-2016 Free Software Foundation, Inc. | ||
| 5 | # This file is free software; the Free Software Foundation | ||
| 6 | # gives unlimited permission to copy and/or distribute it, | ||
| 7 | # with or without modifications, as long as this notice is preserved. | ||
| 8 | |||
| 9 | # Written by Paul Eggert. | ||
| 10 | |||
| 11 | AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER], | ||
| 12 | [ | ||
| 13 | AC_CACHE_CHECK([for flexible array member], | ||
| 14 | ac_cv_c_flexmember, | ||
| 15 | [AC_COMPILE_IFELSE( | ||
| 16 | [AC_LANG_PROGRAM( | ||
| 17 | [[#include <stdlib.h> | ||
| 18 | #include <stdio.h> | ||
| 19 | #include <stddef.h> | ||
| 20 | struct s { int n; double d[]; };]], | ||
| 21 | [[int m = getchar (); | ||
| 22 | size_t nbytes = offsetof (struct s, d) + m * sizeof (double); | ||
| 23 | nbytes += sizeof (struct s) - 1; | ||
| 24 | nbytes -= nbytes % sizeof (struct s); | ||
| 25 | struct s *p = malloc (nbytes); | ||
| 26 | p->d[0] = 0.0; | ||
| 27 | return p->d != (double *) NULL;]])], | ||
| 28 | [ac_cv_c_flexmember=yes], | ||
| 29 | [ac_cv_c_flexmember=no])]) | ||
| 30 | if test $ac_cv_c_flexmember = yes; then | ||
| 31 | AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], | ||
| 32 | [Define to nothing if C supports flexible array members, and to | ||
| 33 | 1 if it does not. That way, with a declaration like 'struct s | ||
| 34 | { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack | ||
| 35 | can be used with pre-C99 compilers. | ||
| 36 | When computing the size of such an object, don't use 'sizeof (struct s)' | ||
| 37 | as it overestimates the size. Use 'offsetof (struct s, d)' instead. | ||
| 38 | Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with | ||
| 39 | MSVC and with C++ compilers.]) | ||
| 40 | else | ||
| 41 | AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1]) | ||
| 42 | fi | ||
| 43 | ]) | ||