[nasm:nasm-2.16.xx] autoconf: add detection of variadic macros support

nasm-bot for H. Peter Anvin hpa at zytor.com
Wed Oct 11 13:39:06 PDT 2023


Commit-ID:  0e7eae99e8c7b3280bf53b183958950b6cfa3bc6
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=0e7eae99e8c7b3280bf53b183958950b6cfa3bc6
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 11 Oct 2023 13:32:00 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Wed, 11 Oct 2023 13:32:52 -0700

autoconf: add detection of variadic macros support

Variadic macros are really useful, even if we can only use them
conditionally.

Unfortunately this means removing -Wc90-c99-compat, because apparently
-Wno-variadic-macros is broken in gcc 13.2. Fortunately it is 2023...

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 autoconf/m4/pa_variadic_macros.m4 | 20 ++++++++++++++++++++
 configure.ac                      | 33 +++++++++++++++++----------------
 2 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/autoconf/m4/pa_variadic_macros.m4 b/autoconf/m4/pa_variadic_macros.m4
new file mode 100644
index 00000000..a2372ce2
--- /dev/null
+++ b/autoconf/m4/pa_variadic_macros.m4
@@ -0,0 +1,20 @@
+dnl --------------------------------------------------------------------------
+dnl PA_VARIADIC_MACROS
+dnl
+dnl Check to see if the compiler supports C99 variadic macros.
+dnl --------------------------------------------------------------------------
+AC_DEFUN([PA_VARIADIC_MACROS],
+[AC_CACHE_CHECK([if $CC supports variadic macros], [pa_cv_variadic_macros],
+[AC_LINK_IFELSE([AC_LANG_SOURCE([
+AC_INCLUDES_DEFAULT
+#define myprintf(f, ...) printf(f, __VA_ARGS__)
+int main(void)
+{
+	myprintf("%s", "Hello, World!\n");
+	return 0;
+}
+])],[pa_cv_variadic_macros=yes],[pa_cv_variadic_macros=no])])
+	AS_IF([test "x$pa_cv_variadic_macros" = xyes],
+	[AC_DEFINE([HAVE_VARIADIC_MACROS], 1,
+[define to 1 if your compiler supports C99 __VA_ARGS__ variadic macros.])])
+])
diff --git a/configure.ac b/configure.ac
index ea0a06c2..0099485c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -149,6 +149,9 @@ AC_C_RESTRICT
 dnl Checks for header files.
 AC_CHECK_INCLUDES_DEFAULT
 
+dnl Check for variadic macro support
+PA_VARIADIC_MACROS
+
 PA_ADD_HEADERS(string.h)
 PA_ADD_HEADERS(stdarg.h)
 PA_ADD_HEADERS(inttypes.h)
@@ -255,7 +258,6 @@ dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
 dnl support these, but don't define __GNUC__ as they don't support
 dnl some other features of gcc.
 dnl
-PA_ADD_CFLAGS([-Werror=attributes])
 PA_COMMON_ATTRIBUTES
 
 dnl
@@ -289,22 +291,8 @@ PA_ARG_DISABLED([pedantic],
 [disable some extra paranoid compiler warnings],
 [],
 [PA_ADD_CFLAGS([-W])
- PA_ADD_CFLAGS([-pedantic])
- PA_ADD_CFLAGS([-Wc90-c99-compat])
- PA_ADD_CFLAGS([-Wc99-compat])
- PA_ADD_CFLAGS([-Wc99-extensions])
+PA_ADD_CFLAGS([-pedantic])
 ])
-dnl Suppress format warning on Windows targets due to their <inttypes.h>
-PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
-PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
-dnl This is needed because we intentionally expect strncpy() to fill
-dnl in a zero-padded (not zero-terminated) buffer in several backends
-PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
-dnl This is needed because we assume 2's-completement signed arithmetic;
-dnl on compilers with gcc-like command line syntax we pass the -fwrapv
-dnl option for exactly that reason.
-PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
-
 dnl Want to turn this on at some point...
 dnl PA_ADD_CFLAGS([-Wwrite-strings])
 PA_ARG_ENABLED([werror],
@@ -322,6 +310,19 @@ PA_ARG_ENABLED([werror],
   PA_ADD_CFLAGS([-Werror=vla])]
 )
 
+dnl Variadic macros are used in this code, but only under explicit guard
+PA_ADD_CFLAGS([-Wvariadic-macros],[-Wno-variadic-macros])
+dnl Suppress format warning on Windows targets due to their <inttypes.h>
+PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
+PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
+dnl This is needed because we intentionally expect strncpy() to fill
+dnl in a zero-padded (not zero-terminated) buffer in several backends
+PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
+dnl This is needed because we assume 2's-completement signed arithmetic;
+dnl on compilers with gcc-like command line syntax we pass the -fwrapv
+dnl option for exactly that reason.
+PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
+
 dnl Warnings that are probabilistic based on the compiler version, and
 dnl only should be used specifically when looking for opportunities to
 dnl address or optimize these cases.


More information about the Nasm-commits mailing list