Skip to content

Commit 15c1c85

Browse files
[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 <[email protected]>
1 parent b08aca7 commit 15c1c85

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

llvm/include/llvm/ADT/Hashing.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ template <typename T> hash_code hash_value(const std::optional<T> &arg) {
677677
template <> struct DenseMapInfo<hash_code, void> {
678678
static inline hash_code getEmptyKey() { return hash_code(-1); }
679679
static inline hash_code getTombstoneKey() { return hash_code(-2); }
680-
static unsigned getHashValue(hash_code val) { return val; }
680+
static unsigned getHashValue(hash_code val) {
681+
return static_cast<unsigned>(size_t(val));
682+
}
681683
static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; }
682684
};
683685

0 commit comments

Comments
 (0)