Skip to content

Commit 5d0e26e

Browse files
authored
[compiler-rt] Make sure __clzdi2 doesn't call itself recursively on sparc64 (#136737)
On 64-bit platforms, libgcc doesn't ship with __clzsi2, so __builtin_clz gets lowered to __clzdi2. A check already exists for GCC, but as of commit 8210ca0 clang also lowers __builtin_clz to __clzdi2 on sparc64. Update the check so that building __clzdi2 with clang/sparc64 also works.
1 parent 4def437 commit 5d0e26e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler-rt/lib/builtins/clzdi2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
// Returns: the number of leading 0-bits
1616

17-
#if !defined(__clang__) && \
18-
((defined(__sparc__) && defined(__arch64__)) || defined(__mips64) || \
17+
#if ((defined(__sparc__) && defined(__arch64__)) || defined(__mips64) || \
1918
(defined(__riscv) && __SIZEOF_POINTER__ >= 8))
2019
// On 64-bit architectures with neither a native clz instruction nor a native
21-
// ctz instruction, gcc resolves __builtin_clz to __clzdi2 rather than
22-
// __clzsi2, leading to infinite recursion.
20+
// ctz instruction, `__builtin_clz` resolves to `__clzdi2` rather than
21+
// __clzsi2 as libgcc does not ship with `__clzsi2`, leading to infinite
22+
// recursion.
2323
#define __builtin_clz(a) __clzsi2(a)
2424
extern int __clzsi2(si_int);
2525
#endif

0 commit comments

Comments
 (0)