From 36cd82c62f5e2b801f205f98e092922ad037393e Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Sat, 17 May 2025 13:29:16 +0800 Subject: [PATCH] [utils] fix clang-tidy false alarm in VerifyOrExit (#11500) Previously, the `VerifyOrExit()` macro's condition caused clang-tidy to issue issue false positives regarding "boolean readability," suggesting simplifications via De Morgan's Theorem. This occurred because the macro wrapped the entire condition and then checked its negative. This commit refactors the macro to evaluate the condition directly, which: 1. Eliminates the erroneous clang-tidy warnings. 2. Potentially enhances CPU branch prediction performance, as the condition is more likely to evaluate to true. --- src/include/common/code_utils.hpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/include/common/code_utils.hpp b/src/include/common/code_utils.hpp index 7f697a420..19f468dcb 100644 --- a/src/include/common/code_utils.hpp +++ b/src/include/common/code_utils.hpp @@ -109,14 +109,17 @@ * @param[in] aCondition A Boolean expression to be evaluated. * @param[in] aAction An optional expression or block to execute when the assertion fails. */ -#define VerifyOrExit(...) \ - do \ - { \ - if (!(OT_FIRST_ARG(__VA_ARGS__))) \ - { \ - OT_SECOND_ARG(__VA_ARGS__); \ - goto exit; \ - } \ +#define VerifyOrExit(...) \ + do \ + { \ + if (OT_FIRST_ARG(__VA_ARGS__)) \ + { \ + } \ + else \ + { \ + OT_SECOND_ARG(__VA_ARGS__); \ + goto exit; \ + } \ } while (false) /**