[llvm] [ADT] DenseMapInfo<unsigned long>::getHashValue - avoid MSVC out of bounds shift warning (PR #96173)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 04:38:15 PDT 2024
https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/96173
Fixes MSVC warning after #95734 - despite it taking the `sizeof(Val) == 4` path, it still warns that the 32-bit unsigned long shift by 32 is out of bounds, so avoid it by converting the hard coded shift amount to be based off sizeof() instead.
>From c213d8cb04abe37bf94ad9389cfcd6ba324d4e2b Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Thu, 20 Jun 2024 12:36:48 +0100
Subject: [PATCH] [ADT] DenseMapInfo<unsigned long>::getHashValue - avoid MSVC
out of bounds shift warning
Fixes MSVC warning after #95734 - despite it taking the `sizeof(Val) == 4` path, it still warns that the 32-bit unsigned long shift by 32 is out of bounds, so avoid it by converting the hard coded shift amount to be based off sizeof() instead.
---
llvm/include/llvm/ADT/DenseMapInfo.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index 4f0aaa1ad48bb..3d83a2c1473f5 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -142,7 +142,7 @@ template<> struct DenseMapInfo<unsigned long> {
if constexpr (sizeof(Val) == 4)
return DenseMapInfo<unsigned>::getHashValue(Val);
else
- return detail::combineHashValue(Val >> 32, Val);
+ return detail::combineHashValue(Val >> (4 * sizeof(Val)), Val);
}
static bool isEqual(const unsigned long& LHS, const unsigned long& RHS) {
More information about the llvm-commits
mailing list