]> xenbits.xensource.com Git - xen.git/commit
xen: make sure that likely and unlikely convert the expression to a boolean
authorIan Campbell <ian.campbell@citrix.com>
Mon, 7 Apr 2014 11:07:04 +0000 (12:07 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 10 Apr 2014 11:11:34 +0000 (12:11 +0100)
commite5545fb6d0dc5e2c48b2e450d18246d9bc1ae35b
tree8c84c37b6e2b3e99146d7365db5c292b4c4967cc
parent40305629dc48a6bfdef52ae5995bfcfb1d59ae8e
xen: make sure that likely and unlikely convert the expression to a boolean

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.

This is mostly likely to affect x86_32 and arm32 builds.  x86_32 is not
present on 4.3 onwards and a quick grep of current staging 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 <ian.campbell@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
xen/include/xen/compiler.h