Skip to content

Commit 475e40d

Browse files
committed
Workaround broken __builtin_clz in clang with MS codegen (#519)
1 parent 24df4b2 commit 475e40d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

fmt/format.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,16 @@ typedef __int64 intmax_t;
287287
# define FMT_ASSERT(condition, message) assert((condition) && message)
288288
#endif
289289

290-
#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
291-
# define FMT_BUILTIN_CLZ(n) __builtin_clz(n)
292-
#endif
290+
// __builtin_clz is broken in clang with Microsoft CodeGen:
291+
// https://github.com/fmtlib/fmt/issues/519
292+
#ifndef _MSC_VER
293+
# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
294+
# define FMT_BUILTIN_CLZ(n) __builtin_clz(n)
295+
# endif
293296

294-
#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll)
295-
# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n)
297+
# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll)
298+
# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n)
299+
# endif
296300
#endif
297301

298302
// Some compilers masquerade as both MSVC and GCC-likes or

0 commit comments

Comments
 (0)