aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2016-09-20 08:30:17 -0700
committerPaul Eggert2016-09-20 08:32:15 -0700
commitd9741b61c8e446de084cc4dc609aaa8e5702118d (patch)
treebc7dee77f208e70918e0c15aa91eb728f27b0c47
parent83fbb3a6dd75e01a768cb6b3348b7c947711ee46 (diff)
downloademacs-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.
-rwxr-xr-xadmin/merge-gnulib2
-rw-r--r--configure.ac2
-rw-r--r--m4/flexmember.m443
-rw-r--r--src/alloc.c16
-rw-r--r--src/conf_post.h10
5 files changed, 53 insertions, 20 deletions
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index 1e3b7599626..ada80b4ae86 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -93,7 +93,7 @@ test -x "$gnulib_srcdir"/gnulib-tool || {
93} 93}
94 94
95"$gnulib_srcdir"/gnulib-tool --dir="$src" $GNULIB_TOOL_FLAGS $GNULIB_MODULES && 95"$gnulib_srcdir"/gnulib-tool --dir="$src" $GNULIB_TOOL_FLAGS $GNULIB_MODULES &&
96rm -- "$src"lib/gl_openssl.h "$src"m4/fcntl-o.m4 "$src"m4/flexmember.m4 \ 96rm -- "$src"lib/gl_openssl.h "$src"m4/fcntl-o.m4 \
97 "$src"m4/gl-openssl.m4 \ 97 "$src"m4/gl-openssl.m4 \
98 "$src"m4/gnulib-cache.m4"$src" m4/warn-on-use.m4 && 98 "$src"m4/gnulib-cache.m4"$src" m4/warn-on-use.m4 &&
99cp -- "$gnulib_srcdir"/build-aux/texinfo.tex "$src"doc/misc && 99cp -- "$gnulib_srcdir"/build-aux/texinfo.tex "$src"doc/misc &&
diff --git a/configure.ac b/configure.ac
index 82a672b8cc5..6488f901e33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -775,8 +775,6 @@ dnl alternative to lib/gnulib.mk, so as to avoid generating header files
775dnl that clash with MinGW. 775dnl that clash with MinGW.
776AM_CONDITIONAL([BUILDING_FOR_WINDOWSNT], [test "x$opsys" = "xmingw32"]) 776AM_CONDITIONAL([BUILDING_FOR_WINDOWSNT], [test "x$opsys" = "xmingw32"])
777 777
778# Skip gnulib's tests for flexible array members, as Emacs assumes C99.
779AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER])
780# Avoid gnulib's tests for -lcrypto, so that there's no static dependency on it. 778# Avoid gnulib's tests for -lcrypto, so that there's no static dependency on it.
781AC_DEFUN([gl_CRYPTO_CHECK]) 779AC_DEFUN([gl_CRYPTO_CHECK])
782# Avoid gnulib's tests for HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW, 780# Avoid gnulib's tests for HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW,
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
11AC_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])
diff --git a/src/alloc.c b/src/alloc.c
index 1092a34801a..41b2f9e77d2 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -2002,9 +2002,9 @@ allocate_string_data (struct Lisp_String *s,
2002 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); 2002 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
2003#endif 2003#endif
2004 2004
2005 b->next_free = b->data; 2005 data = b->data;
2006 b->data[0].string = NULL;
2007 b->next = large_sblocks; 2006 b->next = large_sblocks;
2007 b->next_free = data;
2008 large_sblocks = b; 2008 large_sblocks = b;
2009 } 2009 }
2010 else if (current_sblock == NULL 2010 else if (current_sblock == NULL
@@ -2014,9 +2014,9 @@ allocate_string_data (struct Lisp_String *s,
2014 { 2014 {
2015 /* Not enough room in the current sblock. */ 2015 /* Not enough room in the current sblock. */
2016 b = lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP); 2016 b = lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP);
2017 b->next_free = b->data; 2017 data = b->data;
2018 b->data[0].string = NULL;
2019 b->next = NULL; 2018 b->next = NULL;
2019 b->next_free = data;
2020 2020
2021 if (current_sblock) 2021 if (current_sblock)
2022 current_sblock->next = b; 2022 current_sblock->next = b;
@@ -2025,14 +2025,16 @@ allocate_string_data (struct Lisp_String *s,
2025 current_sblock = b; 2025 current_sblock = b;
2026 } 2026 }
2027 else 2027 else
2028 b = current_sblock; 2028 {
2029 b = current_sblock;
2030 data = b->next_free;
2031 }
2029 2032
2030 data = b->next_free; 2033 data->string = s;
2031 b->next_free = (sdata *) ((char *) data + needed + GC_STRING_EXTRA); 2034 b->next_free = (sdata *) ((char *) data + needed + GC_STRING_EXTRA);
2032 2035
2033 MALLOC_UNBLOCK_INPUT; 2036 MALLOC_UNBLOCK_INPUT;
2034 2037
2035 data->string = s;
2036 s->data = SDATA_DATA (data); 2038 s->data = SDATA_DATA (data);
2037#ifdef GC_CHECK_STRING_BYTES 2039#ifdef GC_CHECK_STRING_BYTES
2038 SDATA_NBYTES (data) = nbytes; 2040 SDATA_NBYTES (data) = nbytes;
diff --git a/src/conf_post.h b/src/conf_post.h
index 865d0183a57..6d54524b970 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -358,16 +358,6 @@ extern int emacs_setenv_TZ (char const *);
358#define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN 358#define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
359#define INLINE_HEADER_END _GL_INLINE_HEADER_END 359#define INLINE_HEADER_END _GL_INLINE_HEADER_END
360 360
361/* To use the struct hack with N elements, declare the struct like this:
362 struct s { ...; t name[FLEXIBLE_ARRAY_MEMBER]; };
363 and allocate (offsetof (struct s, name) + N * sizeof (t)) bytes.
364 IBM xlc 12.1 claims to do C99 but mishandles flexible array members. */
365#ifdef __IBMC__
366# define FLEXIBLE_ARRAY_MEMBER 1
367#else
368# define FLEXIBLE_ARRAY_MEMBER
369#endif
370
371/* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC 361/* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC
372 into not warning incorrectly about use of an uninitialized variable. */ 362 into not warning incorrectly about use of an uninitialized variable. */
373#if defined GCC_LINT || defined lint 363#if defined GCC_LINT || defined lint