From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH v2] eal: force compilation of RTE_ASSERT expression
Date: Tue, 4 Feb 2025 11:46:09 -0800 [thread overview]
Message-ID: <20250204194759.723484-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20250204165516.168106-1-stephen@networkplumber.org>
Even if RTE_ENABLE_ASSERT is not enabled, the expression used should
still be checked for compiler warnings. Use sizeof()
and ternary operator in same manner as the assert() macro to
cause the expression to be evaluated but not generate code.
This was motivated by detection of problems in a driver submission
that was not detected until compiled with non default flags.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v2 - reduce checkpatch complaints and reword comment
lib/eal/include/rte_debug.h | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/eal/include/rte_debug.h b/lib/eal/include/rte_debug.h
index 74593cd4d4..204e6db017 100644
--- a/lib/eal/include/rte_debug.h
+++ b/lib/eal/include/rte_debug.h
@@ -46,8 +46,16 @@ void rte_dump_stack(void);
#ifdef RTE_ENABLE_ASSERT
#define RTE_ASSERT(exp) RTE_VERIFY(exp)
#else
-#define RTE_ASSERT(exp) do {} while (0)
+/*
+ * If RTE_ENABLE_ASSERT is not set, the exp is not checked but not evaluated because
+ * of the use of sizeof(). The ternary operator is to allow function pointers
+ * and bit fields, and to suppress the evaluation of any variable length arrays.
+ */
+#define RTE_ASSERT(exp) do { \
+ (void)sizeof((exp) ? 1 : 0); \
+} while (0)
#endif
+
#define RTE_VERIFY(exp) do { \
if (unlikely(!(exp))) \
rte_panic("line %d\tassert \"%s\" failed\n", __LINE__, #exp); \
--
2.47.2
prev parent reply other threads:[~2025-02-04 19:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-04 16:55 [PATCH] eal: force evaluation " Stephen Hemminger
2025-02-04 19:46 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250204194759.723484-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).