Submitted as an upstream fix
MathExtras has many useful tools. However, they aren't available to use in constexpr equations or functions. Originally this was a patch for swift llvm but it works upstream and as such I have put this PR upstream.
Differential D107240
[LLVM][Support][NFC] Make multiple bitwise MathExtras functions constexpr gAlfonso-bit on Aug 1 2021, 11:35 AM. Authored by
Details
Submitted as an upstream fix MathExtras has many useful tools. However, they aren't available to use in constexpr equations or functions. Originally this was a patch for swift llvm but it works upstream and as such I have put this PR upstream.
Diff Detail
Event TimelineComment Actions Please upload patches with full context using -U999999 per the instructions here https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface
Comment Actions clang-tidy is complaining about function names, but changing every function instance would modify too many files
Comment Actions I copied a chunk of this patch to godbolt and added two different constexpr usages of countLeadingZeros that both fail with MSVC https://godbolt.org/z/Maen4bac4 I'm guessing that because everything is a template, MSVC doesn't diagnose anything until you try to use it in constexpr context.
This comment was removed by gAlfonso-bit.
Comment Actions Is it possible to add unittests showing the count functions being used in constexpr contexts to prove that this will work with MSVC? Comment Actions Unfortunately, as long as we are using c++14, there is actually no easy solution to this Comment Actions @craig.topper I could use the libcpp_clz, which is constexpr, but that seems to be c++ 20 only. |
Doesn't this mean that users of this that want to use it in constexpr can't compile that code with MSVC and would need a different solution just for MSVC? Is that useful for the project?