Commit d64a22a2 authored by Vedant Kumar's avatar Vedant Kumar
Browse files

[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)];
  ...
```
parent 29a4239d
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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)};
  }