Skip to content

[DenseMap] Fix MSVC buildbot failure in lookup_or #142268

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

Merged
merged 2 commits into from
Jun 3, 2025

Conversation

artagnon
Copy link
Contributor

@artagnon artagnon commented May 31, 2025

4bf67cd ([DenseMap] Fix constness issues with lookup_or) introduced a buildbot failure:

https://lab.llvm.org/buildbot/#/builders/63/builds/6559

The patch deviates from the spec and MSVC complains, where it doesn't bind an lvalue to an rvalue reference. Fix it by qualifying the argument of lookup_or with remove_cv_t.

Proof: https://godbolt.org/z/sjTvGMbce

@llvmbot
Copy link
Member

llvmbot commented May 31, 2025

@llvm/pr-subscribers-llvm-adt

Author: Ramkumar Ramachandra (artagnon)

Changes

4bf67cd ([DenseMap] Fix constness issues with lookup_or) introduced a buildbot failure:

https://lab.llvm.org/buildbot/#/builders/63/builds/6559

This seems to be a bug in MSVC, where it doesn't bind an lvalue to an rvalue reference. Work around it by introducing a const-lvalue-reference variant of lookup_or.


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMap.h (+6)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index de41a212c65ab..62a33500e3ad2 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -226,6 +226,12 @@ class DenseMapBase : public DebugEpochBase {
     return Default;
   }
 
+  ValueT lookup_or(const_arg_type_t<KeyT> Val, const ValueT &Default) const {
+    if (const BucketT *Bucket = doFind(Val))
+      return Bucket->getSecond();
+    return Default;
+  }
+
   /// at - Return the entry for the specified key, or abort if no such
   /// entry exists.
   const ValueT &at(const_arg_type_t<KeyT> Val) const {

artagnon and others added 2 commits June 2, 2025 16:32
4bf67cd ([DenseMap] Fix constness issues with lookup_or) introduced a
buildbot failure:

  https://lab.llvm.org/buildbot/#/builders/63/builds/6559

This seems to be a bug in MSVC, where it doesn't bind an lvalue to an
rvalue reference. Work around it by introducing a const-lvalue-reference
variant of lookup_or.
@artagnon artagnon force-pushed the densemap-lookupor-msvc-fix branch from 089fad5 to 5fdd3bf Compare June 2, 2025 15:33
@artagnon artagnon changed the title [DenseMap] Work around a MSVC bug in lookup_or [DenseMap] Fix build failure in lookup_or Jun 2, 2025
Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for updating the patch!

@artagnon artagnon changed the title [DenseMap] Fix build failure in lookup_or [DenseMap] Fix MSVC buildbot failure in lookup_or Jun 2, 2025
@artagnon artagnon merged commit 0838bd6 into llvm:main Jun 3, 2025
11 checks passed
@artagnon artagnon deleted the densemap-lookupor-msvc-fix branch June 3, 2025 10:00
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
4bf67cd ([DenseMap] Fix constness issues with lookup_or) introduced a
buildbot failure:

  https://lab.llvm.org/buildbot/#/builders/63/builds/6559

The patch deviates from the spec and MSVC complains, where it doesn't
bind an lvalue to an rvalue reference. Fix it by qualifying the argument
of lookup_or with remove_cv_t.

Proof: https://godbolt.org/z/sjTvGMbce
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
4bf67cd ([DenseMap] Fix constness issues with lookup_or) introduced a
buildbot failure:

  https://lab.llvm.org/buildbot/#/builders/63/builds/6559

The patch deviates from the spec and MSVC complains, where it doesn't
bind an lvalue to an rvalue reference. Fix it by qualifying the argument
of lookup_or with remove_cv_t.

Proof: https://godbolt.org/z/sjTvGMbce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants