From c7df21071227f7b503936bca68df89755052172e Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Mon, 11 Dec 2023 09:37:57 +0200 Subject: [PATCH] api: hints: fix type conversion problem in odp_unlikely() Convert the argument of odp_unlikely() to boolean before passing it to __builtin_expect() which takes a long int argument. This prevents implementation-defined behaviour when the argument of odp_unlikely() does not fit in a long int. In certain systems with 32-bit long, odp_unlikely() currently turns certain non-zero 64-bit values to zero, breaking the code that is using odp_unlikely(). Signed-off-by: Janne Peltonen Reviewed-by: Matias Elo --- include/odp/api/spec/hints.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/odp/api/spec/hints.h b/include/odp/api/spec/hints.h index 032b483df0..fa5b1b9bb4 100644 --- a/include/odp/api/spec/hints.h +++ b/include/odp/api/spec/hints.h @@ -61,7 +61,7 @@ extern "C" { /** * Branch unlikely taken */ -#define odp_unlikely(x) __builtin_expect((x), 0) +#define odp_unlikely(x) __builtin_expect(!!(x), 0) /* * __builtin_prefetch (const void *addr, rw, locality)