[llvm] [DenseMap] Work around a MSVC bug in lookup_or (PR #142268)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Sat May 31 04:22:15 PDT 2025


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/142268

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.

>From 089fad5b9017afbfc64905ff4bbe5524c390d64f Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <r at artagnon.com>
Date: Sat, 31 May 2025 13:16:35 +0200
Subject: [PATCH] [DenseMap] Work around a MSVC bug in lookup_or

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.
---
 llvm/include/llvm/ADT/DenseMap.h | 6 ++++++
 1 file changed, 6 insertions(+)

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 {



More information about the llvm-commits mailing list