Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 314d8fb

Browse files
authored
Merge pull request #27 from xen0n/dont-recurse
Workaround LLVM bug 11663
2 parents 3bc0272 + ac3aa6b commit 314d8fb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/builtins/int_lib.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@
7272
/* Include internal utility function declarations. */
7373
#include "int_util.h"
7474

75+
/*
76+
* Workaround for LLVM bug 11663. Prevent endless recursion in
77+
* __c?zdi2(), where calls to __builtin_c?z() are expanded to
78+
* __c?zdi2() instead of __c?zsi2().
79+
*
80+
* Instead of placing this workaround in c?zdi2.c, put it in this
81+
* global header to prevent other C files from making the detour
82+
* through __c?zdi2() as well.
83+
*
84+
* This problem has been observed on FreeBSD for sparc64 and
85+
* mips64 with GCC 4.2.1, and for riscv with GCC 5.2.0.
86+
* Presumably it's any version of GCC, and targeting an arch that
87+
* does not have dedicated bit counting instructions.
88+
*/
89+
#if (defined(__sparc64__) || defined(__mips_n64) || defined(__mips_o64) || defined(__riscv__) \
90+
|| (_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIO64))
91+
si_int __clzsi2(si_int);
92+
si_int __ctzsi2(si_int);
93+
#define __builtin_clz __clzsi2
94+
#define __builtin_ctz __ctzsi2
95+
#endif /* sparc64 || mips_n64 || mips_o64 || riscv */
96+
7597
COMPILER_RT_ABI si_int __paritysi2(si_int a);
7698
COMPILER_RT_ABI si_int __paritydi2(di_int a);
7799

0 commit comments

Comments
 (0)