Skip to content

Commit

Permalink
[LLVM][ADT] Convert llvm::hash_code to unsigned explicitly in DenseMa…
Browse files Browse the repository at this point in the history
…pInfo (#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@intel.com>
  • Loading branch information
andrey-golubev and OrestChura committed Jan 18, 2024
1 parent b08aca7 commit 15c1c85
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion llvm/include/llvm/ADT/Hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

Expand Down

0 comments on commit 15c1c85

Please sign in to comment.