-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[IR] Simplify HasCachedHash with is_detected (NFC) #159510
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
[IR] Simplify HasCachedHash with is_detected (NFC) #159510
Conversation
With is_detected, we don't need to implement a SFINAE trick on our own.
@llvm/pr-subscribers-llvm-ir Author: Kazu Hirata (kazutakahirata) ChangesWith is_detected, we don't need to implement a SFINAE trick on our own. Full diff: https://github.com/llvm/llvm-project/pull/159510.diff 1 Files Affected:
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index fc78a5b299f49..09e25ceaf59c3 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -986,15 +986,10 @@ static T *uniquifyImpl(T *N, DenseSet<T *, InfoT> &Store) {
}
template <class NodeTy> struct MDNode::HasCachedHash {
- using Yes = char[1];
- using No = char[2];
- template <class U, U Val> struct SFINAE {};
-
template <class U>
- static Yes &check(SFINAE<void (U::*)(unsigned), &U::setHash> *);
- template <class U> static No &check(...);
+ using check = decltype(static_cast<void (U::*)(unsigned)>(&U::setHash));
- static const bool value = sizeof(check<NodeTy>(nullptr)) == sizeof(Yes);
+ static constexpr bool value = is_detected<check, NodeTy>::value;
};
MDNode *MDNode::uniquify() {
|
Hi, I have no idea what is happening but I noticed that if we build this patch with clang (wer're using 18.1) and run lit tests then the following tests fail:
One example of a failure:
If we build with gcc (13.3) everything seem to work. So something funny seems to happen, at least when using clang 18.1. Does anyone else see this? |
@mikaelholmen, I'm also seeing the following tests fail locally as a result of this commit:
However, I haven't root caused this. (i.e. perhaps these failures can be attributed to a local change) For context, here's a subset of my build configuration:
I have not tried building with |
Also see it on the bazel buildbots, which bisects to this change: https://buildkite.com/llvm-project/upstream-bazel/builds/151045 |
I've reproduced the failure with clang version 18.1.8. I ran the two versions side by side:
The
even though
|
This check is weird -- I'd expect something like |
This patch modernizes HasCachedHash. - "struct SFINAE" is replaced with identically defined SameType. - The return types Yes and No are replaced with std::true_type and std::false_type. My previous attempt (llvm#159510) to clean up HasCachedHash failed on clang++-18, but this version works with clang++-18.
@kuhar I don't mean to dig too deep into this, but I played with a reduced testcase of |
This patch modernizes HasCachedHash. - "struct SFINAE" is replaced with identically defined SameType. - The return types Yes and No are replaced with std::true_type and std::false_type. My previous attempt (#159510) to clean up HasCachedHash failed on clang++-18, but this version works with clang++-18.
With is_detected, we don't need to implement a SFINAE trick on our own.