[nasm:nasm-2.16.xx] error: macro to bypass disabled warning generation

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


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

error: macro to bypass disabled warning generation

At least attempt to not spend time generating a warning message that
is just going to be suppressed.

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


---
 asm/error.c     |  5 ++++-
 include/error.h | 25 +++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/asm/error.c b/asm/error.c
index 192555de..6e3d881c 100644
--- a/asm/error.c
+++ b/asm/error.c
@@ -81,8 +81,11 @@ nasm_err_helpers(fatal_func, panic,    ERR_PANIC)
  * Strongly discourage warnings without level by require flags on warnings.
  * This means nasm_warn() is the equivalent of the -f variants of the
  * other ones.
+ *
+ * This is wrapped in a macro to be able to elide it if the warning is
+ * disabled, hence the extra underscore.
  */
-void nasm_warn(errflags flags, const char *fmt, ...)
+void nasm_warn_(errflags flags, const char *fmt, ...)
 {
 	nasm_do_error(ERR_WARNING, flags);
 }
diff --git a/include/error.h b/include/error.h
index e6338c98..af0b7c4e 100644
--- a/include/error.h
+++ b/include/error.h
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2020 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2023 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -60,7 +60,7 @@ void printf_func(1, 2) nasm_debug(const char *fmt, ...);
 void printf_func(2, 3) nasm_debugf(errflags flags, const char *fmt, ...);
 void printf_func(1, 2) nasm_info(const char *fmt, ...);
 void printf_func(2, 3) nasm_infof(errflags flags, const char *fmt, ...);
-void printf_func(2, 3) nasm_warn(errflags flags, const char *fmt, ...);
+void printf_func(2, 3) nasm_warn_(errflags flags, const char *fmt, ...);
 void printf_func(1, 2) nasm_nonfatal(const char *fmt, ...);
 void printf_func(2, 3) nasm_nonfatalf(errflags flags, const char *fmt, ...);
 fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
@@ -145,6 +145,27 @@ void nasm_error_hold_pop(errhold hold, bool issue);
 /* Should be included from within error.h only */
 #include "warnings.h"
 
+/* True if a warning is enabled, either as a warning or an error */
+static inline bool warn_active(errflags warn)
+{
+    enum warn_index wa = WARN_IDX(warn);
+    return unlikely(warning_state[wa] & WARN_ST_ENABLED);
+}
+
+#ifdef HAVE_VARIADIC_MACROS
+
+#define nasm_warn(w, ...) \
+    do { \
+        if (unlikely(warn_active(w))) \
+            nasm_warn_(w, __VA_ARGS__); \
+    } while (0)
+
+#else
+
+#define nasm_warn nasm_warn_
+
+#endif
+
 /* By defining MAX_DEBUG, we can compile out messages entirely */
 #ifndef MAX_DEBUG
 # define MAX_DEBUG (~0U)


More information about the Nasm-commits mailing list