diff options
author | Peter Simons <simons@cryp.to> | 2023-02-20 17:19:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-20 17:19:33 +0100 |
commit | ac2e553eee1eb831df43f3db40b7d77f0104e823 (patch) | |
tree | 01db50ebb815e63e01190f558ea5b33faec8b98f | |
parent | d18f0e05a3dda76d9f73fdd9594259087170b834 (diff) | |
parent | 6253fdae1dfc9b3449066ad0e996c5aea268bc1e (diff) | |
download | autoconf-archive-ac2e553eee1eb831df43f3db40b7d77f0104e823.tar.gz |
Merge pull request #271 from rurban/restrict
Add ax_c_restrict
-rw-r--r-- | m4/ax_c_restrict.m4 | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/m4/ax_c_restrict.m4 b/m4/ax_c_restrict.m4 new file mode 100644 index 0000000..1ca9e71 --- /dev/null +++ b/m4/ax_c_restrict.m4 @@ -0,0 +1,62 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_c_restrict.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_C_RESTRICT +# +# DESCRIPTION +# +# This macro checks if the C99 restrict keyword is broken with the current +# compiler and optimizations settings. If broken, it undefines restrict to +# do no harm. As of 2019 gcc since 5.0 and clang since 6.0 (June 2017) are +# known to be broken and not yet fixed. See +# https://github.com/rust-lang/rust/issues/54878 with the links to the gcc +# and clang tickets. +# +# LICENSE +# +# Copyright (c) 2019 Reini Urban <rurban@cpan.org> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([AX_C_RESTRICT], +[AC_CACHE_CHECK([for restrict usability], + [ax_cv_c_restrict_usable], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([], + [[ + void copy (int * restrict to, int * restrict from) { + *to = *from; + } + void test (int *a, int *b) { + for (int i = 0; i < 4; i++) { + copy (&b[i & 1], &a[i & 1]); + } + } + int main () { + int ary[] = {0, 1, 2}; + test (&ary[1], &ary[0]); + /* printf("%d %d %d\n", ary[0], ary[1], ary[2]); + 2 2 2 is correct + 1 2 2 wrong */ + return ary[0] == 2 ? 0 : 1; + } + ]])], + [ax_cv_c_restrict_usable=restrict], + [ax_cv_c_restrict_usable=], + [ax_cv_c_restrict_usable=])]) + +if test -z $ax_cv_c_restrict_usable; then + AC_MSG_RESULT([no]) + AC_DEFINE_UNQUOTED(restrict, $ax_cv_c_restrict_usable, + [If restrict is broken with this C compiler]) +else + AC_MSG_RESULT([yes]) +fi +]) dnl AX_C_RESTRICT |