[llvm] [LLVM] Slay undead copysign code (PR #111269)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 5 22:00:06 PDT 2024


================
@@ -438,7 +442,15 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
     break;
   }
   case Intrinsic::copysign: {
-    ReplaceFPIntrinsicWithCall(CI, "copysignf", "copysign", "copysignl");
+    switch (CI->getArgOperand(0)->getType()->getTypeID()) {
+    default:
+      assert(false && "only need a copysign libcall for arch-specific floats");
----------------
workingjubilee wrote:

Because its name is usually false[^1][^2][^3][^4][^5][^6][^7], and if LLVM is compiled with `LLVM_UNREACHABLE_OPTIMIZE=ON`, then:
> When ON (default) then llvm_unreachable() is considered "undefined behavior" and optimized as such. When OFF it is instead replaced with a guaranteed "trap".

I am not great at reading C++, but the code here does not seem to have a type-checked guarantee enforcing that this is _actually_ unreachable. It is relying on callers not calling it in a mistaken way. The required invariant is not even documented as causing UB if violated, as far as I can tell: https://github.com/llvm/llvm-project/blob/6de5305b3d7a4a19a29b35d481a8090e2a6d3a7e/llvm/include/llvm/CodeGen/IntrinsicLowering.h#L27-L42

Is there such a guarantee that I am not seeing?

[^1]: https://github.com/llvm/llvm-project/issues/62012
[^2]: https://github.com/llvm/llvm-project/issues/104718
[^3]: https://github.com/llvm/llvm-project/issues/62252
[^4]: https://github.com/llvm/llvm-project/issues/59017
[^5]: https://github.com/llvm/llvm-project/issues/109251
[^6]: https://github.com/llvm/llvm-project/issues/48149
[^7]: https://github.com/llvm/llvm-project/issues/85783

https://github.com/llvm/llvm-project/pull/111269


More information about the llvm-commits mailing list