From 1567e4bd07b4ff64f082745fad01d1efcc8e1c0c Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Tue, 7 Oct 2014 22:19:41 +0200 Subject: [PATCH] configurator: Fix CTZ detection The literal "1" in "1 << (sizeof(long{, long})*8 - 1)" should be 1L or 1LL, so that the expression has the right type. Otherwise, the shift is only by 31 bits on x86 (other platforms may behave differently). To avoid language lawyers shouting UB at me, and since __builtin_ctz{,l,ll} formally takes unsigned parameters, use UL and ULL suffixes. Also, fix a typo (missing parenthesis) in the code for CTZLL causing the detection of __builtin_ctzll to always fail for the wrong reason. Signed-off-by: Rasmus Villemoes Signed-off-by: Rusty Russell --- tools/configurator/configurator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c index d1aa5c61..51ac8fbf 100644 --- a/tools/configurator/configurator.c +++ b/tools/configurator/configurator.c @@ -117,9 +117,9 @@ static struct test tests[] = { { "HAVE_BUILTIN_CTZ", INSIDE_MAIN, NULL, NULL, "return __builtin_ctz(1 << (sizeof(int)*8 - 1)) == (sizeof(int)*8 - 1) ? 0 : 1;" }, { "HAVE_BUILTIN_CTZL", INSIDE_MAIN, NULL, NULL, - "return __builtin_ctzl(1 << (sizeof(long)*8 - 1)) == (sizeof(long)*8 - 1) ? 0 : 1;" }, + "return __builtin_ctzl(1UL << (sizeof(long)*8 - 1)) == (sizeof(long)*8 - 1) ? 0 : 1;" }, { "HAVE_BUILTIN_CTZLL", INSIDE_MAIN, NULL, NULL, - "return __builtin_ctzll(1 << (sizeof(long long)*8 - 1) == (sizeof(long long)*8 - 1) ? 0 : 1;" }, + "return __builtin_ctzll(1ULL << (sizeof(long long)*8 - 1)) == (sizeof(long long)*8 - 1) ? 0 : 1;" }, { "HAVE_BUILTIN_CONSTANT_P", INSIDE_MAIN, NULL, NULL, "return __builtin_constant_p(1) ? 0 : 1;" }, { "HAVE_BUILTIN_EXPECT", INSIDE_MAIN, NULL, NULL, -- 2.39.2