From 8fa9acb8e5d28180aa402269757cd7dda62c70b0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 1 Feb 2018 16:43:16 -0800 Subject: [PATCH] Workaround broken __builtin_clz in clang with MS codegen (#519) --- include/fmt/format.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 648a0c57..3846ba70 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -140,12 +140,16 @@ # endif #endif -#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) -# define FMT_BUILTIN_CLZ(n) __builtin_clz(n) -#endif +// __builtin_clz is broken in clang with Microsoft CodeGen: +// https://github.com/fmtlib/fmt/issues/519 +#ifndef _MSC_VER +# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) +# define FMT_BUILTIN_CLZ(n) __builtin_clz(n) +# endif -#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) -# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) +# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) +# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) +# endif #endif // Some compilers masquerade as both MSVC and GCC-likes or otherwise support