Skip to content

fix ConstantFoldFP128 params #98394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

walkingeyerobot
Copy link

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.

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).
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2024

@llvm/pr-subscribers-llvm-analysis

Author: None (walkingeyerobot)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/98394.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/ConstantFolding.cpp (+1-1)
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());

@walkingeyerobot
Copy link
Author

cc @MDevereau, who I believe authored this block a few weeks ago.

@efriedma-quic
Copy link
Collaborator

See #96287.

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff dad7442aff5c85ff9141b0d0f231bcd731cbadc6 893844e4b3332c6e8e85cf3f020f31bee6fda4ab --extensions cpp -- llvm/lib/Analysis/ConstantFolding.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index ca82f10f1f..d223d504e7 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1784,8 +1784,8 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
 }
 
 #if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
-Constant *ConstantFoldFP128(float128 (*NativeFP)(float128),
-                            const APFloat &V, Type *Ty) {
+Constant *ConstantFoldFP128(float128 (*NativeFP)(float128), const APFloat &V,
+                            Type *Ty) {
   llvm_fenv_clearexcept();
   float128 Result = NativeFP(V.convertToQuad());
   if (llvm_fenv_testexcept()) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants