[LiveDebugValues] Prevent some misuse of LocIndex::fromRawInteger, NFC

Make it a compile-time error to pass an int/unsigned/etc to
fromRawInteger.

Hopefully this prevents errors of the form:

```
for (unsigned ID : getVarLocs()) {
  auto VL = LocMap[LocIndex::fromRawInteger(ID)];
  ...
```
This commit is contained in:
Vedant Kumar 2020-03-02 16:56:17 -08:00
parent 29a4239d31
commit d64a22a2ad
1 changed files with 4 additions and 1 deletions

View File

@ -138,7 +138,10 @@ struct LocIndex {
return (static_cast<uint64_t>(Location) << 32) | Index;
}
static LocIndex fromRawInteger(uint64_t ID) {
template<typename IntT> static LocIndex fromRawInteger(IntT ID) {
static_assert(std::is_unsigned<IntT>::value &&
sizeof(ID) == sizeof(uint64_t),
"Cannot convert raw integer to LocIndex");
return {static_cast<uint32_t>(ID >> 32), static_cast<uint32_t>(ID)};
}