[PATCH] D42902: [compiler-rt] Workaround for endless recursion in ctzdi2

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 06:23:01 PST 2018


JDevlieghere updated this revision to Diff 132817.
JDevlieghere added a comment.

Feedback Joerg: go with NetBSD's workaround.


https://reviews.llvm.org/D42902

Files:
  compiler-rt/lib/builtins/clzdi2.c
  compiler-rt/lib/builtins/ctzdi2.c


Index: compiler-rt/lib/builtins/ctzdi2.c
===================================================================
--- compiler-rt/lib/builtins/ctzdi2.c
+++ compiler-rt/lib/builtins/ctzdi2.c
@@ -16,6 +16,12 @@
 
 /* Returns: the number of trailing 0-bits  */
 
+#if !defined(__clang__) && (defined(__sparc64__) || defined(__mips64) || defined(__riscv__))
+/* gcc resolves __builtin_ctz -> __ctzdi2 leading to infinite recursion */
+#define __builtin_ctz(a) __ctzsi2(a)
+extern si_int __ctzsi2(si_int);
+#endif
+
 /* Precondition: a != 0 */
 
 COMPILER_RT_ABI si_int
Index: compiler-rt/lib/builtins/clzdi2.c
===================================================================
--- compiler-rt/lib/builtins/clzdi2.c
+++ compiler-rt/lib/builtins/clzdi2.c
@@ -16,6 +16,12 @@
 
 /* Returns: the number of leading 0-bits */
 
+#if !defined(__clang__) && (defined(__sparc64__) || defined(__mips64) || defined(__riscv__))
+/* gcc resolves __builtin_clz -> __clzdi2 leading to infinite recursion */
+#define __builtin_clz(a) __clzsi2(a)
+extern si_int __clzsi2(si_int);
+#endif
+
 /* Precondition: a != 0 */
 
 COMPILER_RT_ABI si_int


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42902.132817.patch
Type: text/x-patch
Size: 1118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180205/d182e5fc/attachment.bin>


More information about the llvm-commits mailing list