[llvm] [DenseMap] Work around a MSVC bug in lookup_or (PR #142268)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sat May 31 04:22:53 PDT 2025
    
    
  
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Ramkumar Ramachandra (artagnon)
<details>
<summary>Changes</summary>
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
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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/142268
    
    
More information about the llvm-commits
mailing list