[llvm] 15c1c85 - [LLVM][ADT] Convert llvm::hash_code to unsigned explicitly in DenseMapInfo (#77743)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 09:16:52 PST 2024


Author: Andrei Golubev
Date: 2024-01-19T04:16:48+11:00
New Revision: 15c1c85470a17283bd86fe68a702c74599bdcb5c

URL: https://github.com/llvm/llvm-project/commit/15c1c85470a17283bd86fe68a702c74599bdcb5c
DIFF: https://github.com/llvm/llvm-project/commit/15c1c85470a17283bd86fe68a702c74599bdcb5c.diff

LOG: [LLVM][ADT] Convert llvm::hash_code to unsigned explicitly in DenseMapInfo (#77743)

The getHashValue() signature returns a value of type 'unsigned' while
the hash_code could only be implicitly converted to 'size_t'. Depending
on the C++ implementation, this may or may not be a narrowing
conversion.

On some platform/compiler combination, this becomes a warning. To avoid
the warning (and better highlight the narrowing), do an explicit
conversion instead.

Co-authored-by: Orest Chura <orest.chura at intel.com>

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Hashing.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
index 4e82ba9a6fba2a5..a5477362a507939 100644
--- a/llvm/include/llvm/ADT/Hashing.h
+++ b/llvm/include/llvm/ADT/Hashing.h
@@ -677,7 +677,9 @@ template <typename T> hash_code hash_value(const std::optional<T> &arg) {
 template <> struct DenseMapInfo<hash_code, void> {
   static inline hash_code getEmptyKey() { return hash_code(-1); }
   static inline hash_code getTombstoneKey() { return hash_code(-2); }
-  static unsigned getHashValue(hash_code val) { return val; }
+  static unsigned getHashValue(hash_code val) {
+    return static_cast<unsigned>(size_t(val));
+  }
   static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; }
 };
 


        


More information about the llvm-commits mailing list