This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Workaround for endless recursion in ctzdi2
ClosedPublic

Authored by JDevlieghere on Feb 5 2018, 3:18 AM.

Details

Summary

Workaround for LLVM bug 11663. Prevent endless recursion in
c?zdi2(), where calls to builtin_c?z() are expanded to
c?zdi2() instead of c?zsi2().

Instead of placing this workaround in c?zdi2.c, put it in this global
header to prevent other C files from making the detour through
__c?zdi2() as well.

This problem has been observed on FreeBSD for sparc64 and mips64 with
GCC 4.2.1, and for riscv with GCC 5.2.0. Presumably it's any version of
GCC, and targeting an arch that does not have dedicated bit counting
instructions.

PR: https://bugs.llvm.org/show_bug.cgi?id=11663

This problem was brought to my attention by Adrian Glaubitz yesterday at
FOSDEM. He asked me if I could help him get this upstream. The workaround is
already present in Rust's version of compiler-rt, but obviously they'd like to have
this upstream: https://github.com/rust-lang/compiler-rt/pull/35/files

Diff Detail

Event Timeline

JDevlieghere created this revision.Feb 5 2018, 3:18 AM
joerg added a comment.Feb 5 2018, 5:45 AM

I really, really dislike this patch. It is using very blunt force to workaround a GCC bug. The comment is too verbose as well. Please try the following change from NetBSD instead:

https://github.com/NetBSD/src/commit/76ddb1c005bace0912c6091434e0e6560942bf7f#diff-13bc0724eb7139f6dec41626560c0ba7

Feedback Joerg: go with NetBSD's workaround.

compnerd accepted this revision.Feb 6 2018, 9:06 AM

I believe that the commit message needs to be updated for the change. This is a pretty distasteful patch IMO, but, I don't see a better solution here :-(.

This revision is now accepted and ready to land.Feb 6 2018, 9:06 AM
This revision was automatically updated to reflect the committed changes.