[llvm] fix ConstantFoldFP128 params (PR #98394)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 14:35:06 PDT 2024


https://github.com/walkingeyerobot created https://github.com/llvm/llvm-project/pull/98394

I ran into this error while building:
```
llvm/lib/Analysis/ConstantFolding.cpp:2129:16: error: no matching function for call to 'ConstantFoldFP128'
 2129 |         return ConstantFoldFP128(logf128, Op->getValueAPF(), Ty);
      |                ^~~~~~~~~~~~~~~~~
llvm/lib/Analysis/ConstantFolding.cpp:1787:11: note: candidate function not viable: no known conversion from '_Float128 (_Float128) throw()' (aka '__float128 (__float128) throw()') to 'long double (*)(long double)' for 1st argument
 1787 | Constant *ConstantFoldFP128(long double (*NativeFP)(long double),
      |           ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```

I'm pretty sure switching from `long double` to `float128` is correct here, and that certainly makes it work on my machine.

with glibc, logf128 is not available when compiling with clang and it is available with gcc. But, in llvm, has_float128 define isn't set unless you're using clang. So the combination of those means this block ~never actually gets used (unless you're doing something weird like I am).

This fixes what happens when this block is used, but doesn't address it actually being used.

>From 893844e4b3332c6e8e85cf3f020f31bee6fda4ab Mon Sep 17 00:00:00 2001
From: walkingeyerobot <mitch at thefoley.net>
Date: Wed, 10 Jul 2024 17:29:57 -0400
Subject: [PATCH] fix ConstantFoldFP128 params

I ran into this error while building:
```
/google/src/cloud/mitchfoley/sync_emscripten2/google3/third_party/crosstool/v18/stable/wrappers/bin/clang++ -DGTEST_HAS_RTTI=0 -DHAS_LOGF128 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/local/google/home/mitchfoley/repos/llvm-project/lib/Analysis -I/usr/local/google/home/mitchfoley/repos/llvm-project/llvm/lib/Analysis -I/usr/local/google/home/mitchfoley/repos/llvm-project/include -I/usr/local/google/home/mitchfoley/repos/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT lib/Analysis/CMakeFiles/LLVMAnalysis.dir/ConstantFolding.cpp.o -MF lib/Analysis/CMakeFiles/LLVMAnalysis.dir/ConstantFolding.cpp.o.d -o lib/Analysis/CMakeFiles/LLVMAnalysis.dir/ConstantFolding.cpp.o -c /usr/local/google/home/mitchfoley/repos/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp                                                                                                                                              /usr/local/google/home/mitchfoley/repos/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp:2129:16: error: no matching function for call to 'ConstantFoldFP128'           2129 |         return ConstantFoldFP128(logf128, Op->getValueAPF(), Ty);                                                                                                      |                ^~~~~~~~~~~~~~~~~                                                                                                                                 /usr/local/google/home/mitchfoley/repos/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp:1787:11: note: candidate function not viable: no known conversion from '_Float128 (_Float128) throw()' (aka '__float128 (__float128) throw()') to 'long double (*)(long double)' for 1st argument                                                       1787 | Constant *ConstantFoldFP128(long double (*NativeFP)(long double),                                                                                                      |           ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

with glibc, logf128 is not available when compiling with clang and it is available with gcc. But, in llvm, has_float128 define isn't set unless you're using clang. So the combination of those means this block ~never actually gets used (unless you're doing something weird like I am).
---
 llvm/lib/Analysis/ConstantFolding.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 962880f68f076..ca82f10f1ffd4 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1784,7 +1784,7 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
 }
 
 #if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
-Constant *ConstantFoldFP128(long double (*NativeFP)(long double),
+Constant *ConstantFoldFP128(float128 (*NativeFP)(float128),
                             const APFloat &V, Type *Ty) {
   llvm_fenv_clearexcept();
   float128 Result = NativeFP(V.convertToQuad());



More information about the llvm-commits mailing list