From 2ffdb74fb1b12e9f3730d0f152b795838934547d Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 17 Jun 2020 19:30:53 +0000 Subject: Use (and ignore) the expression provided to log_assert in NDEBUG builds. This avoids warnings in NDEBUG builds emitted when a variable is only used in log_assert, but is always defined. --- kernel/log.h | 2 +- kernel/macc.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'kernel') diff --git a/kernel/log.h b/kernel/log.h index 501d20c09..ef4b6b456 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -236,7 +236,7 @@ static inline void log_assert_worker(bool cond, const char *expr, const char *fi } # define log_assert(_assert_expr_) YOSYS_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, __FILE__, __LINE__) #else -# define log_assert(_assert_expr_) +# define log_assert(_assert_expr_) do { if (0) { (void)(_assert_expr_); } } while(0) #endif #define log_abort() YOSYS_NAMESPACE_PREFIX log_error("Abort in %s:%d.\n", __FILE__, __LINE__) diff --git a/kernel/macc.h b/kernel/macc.h index e9f6f05e9..d216e6772 100644 --- a/kernel/macc.h +++ b/kernel/macc.h @@ -107,10 +107,8 @@ struct Macc std::vector config_bits = cell->getParam(ID::CONFIG).bits; int config_cursor = 0; -#ifndef NDEBUG int config_width = cell->getParam(ID::CONFIG_WIDTH).as_int(); log_assert(GetSize(config_bits) >= config_width); -#endif int num_bits = 0; if (config_bits[config_cursor++] == State::S1) num_bits |= 1; -- cgit v1.2.3 From 21692c4a2e0e70d6e0d09dd0b3c93ff70f1f236e Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 19 Jun 2020 01:51:53 +0000 Subject: Use (and ignore) the expression provided to log_debug in NDEBUG builds. --- kernel/log.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'kernel') diff --git a/kernel/log.h b/kernel/log.h index ef4b6b456..9935a9271 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -157,11 +157,10 @@ void log_warning_noprefix(const char *format, ...) YS_ATTRIBUTE(format(printf, 1 #ifndef NDEBUG static inline bool ys_debug(int n = 0) { if (log_force_debug) return true; log_debug_suppressed += n; return false; } -# define log_debug(...) do { if (ys_debug(1)) log(__VA_ARGS__); } while (0) #else static inline bool ys_debug(int = 0) { return false; } -# define log_debug(_fmt, ...) do { } while (0) #endif +# define log_debug(...) do { if (ys_debug(1)) log(__VA_ARGS__); } while (0) static inline void log_suppressed() { if (log_debug_suppressed && !log_make_debug) { -- cgit v1.2.3 From 118e4caa37aa437974d9ec2ac65a4c6048cf6291 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 19 Jun 2020 01:32:48 +0000 Subject: Remove YS_ATTRIBUTE(unused) where present just for log_assert()/log_debug(). --- kernel/log.h | 2 +- kernel/modtools.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'kernel') diff --git a/kernel/log.h b/kernel/log.h index 9935a9271..e9d09d0da 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -370,7 +370,7 @@ static inline void log_dump_val_worker(char *v) { log("%s", v); } static inline void log_dump_val_worker(const char *v) { log("%s", v); } static inline void log_dump_val_worker(std::string v) { log("%s", v.c_str()); } static inline void log_dump_val_worker(PerformanceTimer p) { log("%f seconds", p.sec()); } -static inline void log_dump_args_worker(const char *p YS_ATTRIBUTE(unused)) { log_assert(*p == 0); } +static inline void log_dump_args_worker(const char *p) { log_assert(*p == 0); } void log_dump_val_worker(RTLIL::IdString v); void log_dump_val_worker(RTLIL::SigSpec v); void log_dump_val_worker(RTLIL::State v); diff --git a/kernel/modtools.h b/kernel/modtools.h index 9d6a50502..29c510059 100644 --- a/kernel/modtools.h +++ b/kernel/modtools.h @@ -169,7 +169,7 @@ struct ModIndex : public RTLIL::Monitor port_add(cell, port, sig); } - void notify_connect(RTLIL::Module *mod YS_ATTRIBUTE(unused), const RTLIL::SigSig &sigsig) override + void notify_connect(RTLIL::Module *mod, const RTLIL::SigSig &sigsig) override { log_assert(module == mod); @@ -214,13 +214,13 @@ struct ModIndex : public RTLIL::Monitor } } - void notify_connect(RTLIL::Module *mod YS_ATTRIBUTE(unused), const std::vector&) override + void notify_connect(RTLIL::Module *mod, const std::vector&) override { log_assert(module == mod); auto_reload_module = true; } - void notify_blackout(RTLIL::Module *mod YS_ATTRIBUTE(unused)) override + void notify_blackout(RTLIL::Module *mod) override { log_assert(module == mod); auto_reload_module = true; -- cgit v1.2.3 From c8c3c7af87804a175b3dfc60dce191b03c9741fe Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 19 Jun 2020 15:45:52 +0000 Subject: Use [[maybe_unused]] instead of YS_ATTRIBUTE(unused). [[maybe_unused]] is available since C++17, so this commit adds a polyfill YS_MAYBE_UNUSED. Once we require C++17 we can drop it. --- kernel/yosys.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'kernel') diff --git a/kernel/yosys.h b/kernel/yosys.h index b9b6b24b1..f1646d6bc 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -144,6 +144,14 @@ extern Tcl_Obj *Tcl_ObjSetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *p # define YS_ATTRIBUTE(...) #endif +#if __cplusplus >= 201703L +# define YS_MAYBE_UNUSED [[maybe_unused]]; +#elif defined(__GNUC__) || defined(__clang__) +# define YS_MAYBE_UNUSED __attribute__((__unused__)) +#else +# define YS_MAYBE_UNUSED +#endif + #if __cplusplus >= 201703L # define YS_FALLTHROUGH [[fallthrough]]; #elif defined(__clang__) -- cgit v1.2.3