From: Ian Campbell Subject: [PATCH] xen: make sure that likely and unlikely convert the expression to a boolean Date: Mon, 7 Apr 2014 12:07:04 +0100 Message-ID: <1396868824-16769-1-git-send-email-ian.campbell@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: keir@xen.org Cc: Tim Deegan , Ian Campbell , Jan Beulich , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org According to http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html __builtin_expect has the prototype: long __builtin_expect (long exp, long c) If sizeof(exp) > sizeof(long) then this will effectively mask off the top bits of exp, meaning that the if in "if (unlikey(x))" will see the masked version, which might be false when true was expected, likely has the same issue. With the x86_32 hypervisor no longer existing this is mostly likely to affect arm32 builds. A quick grep however shows that all the existing arm32 uses of both likely and unlikely already pass a boolean. I noticed this with an as yet unposted patch which did not have this property. Also the defintion of likely might not have had the expected affect for cases where a true value > 1 might be passed. Signed-off-by: Ian Campbell Cc: Keir Fraser Cc: Jan Beulich Cc: Tim Deegan --- xen/include/xen/compiler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h index 6e07990..4b3472d 100644 --- a/xen/include/xen/compiler.h +++ b/xen/include/xen/compiler.h @@ -7,8 +7,8 @@ #define barrier() __asm__ __volatile__("": : :"memory") -#define likely(x) __builtin_expect((x),1) -#define unlikely(x) __builtin_expect((x),0) +#define likely(x) __builtin_expect(!!(x),1) +#define unlikely(x) __builtin_expect(!!(x),0) #define inline __inline__ #define always_inline __inline__ __attribute__ ((always_inline)) -- 1.7.10.4