Skip to content

Commit

Permalink
[LiveDebugValues] Prevent some misuse of LocIndex::fromRawInteger, NFC
Browse files Browse the repository at this point in the history
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)];
  ...
```
  • Loading branch information
vedantk committed Mar 3, 2020
1 parent 29a4239 commit d64a22a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/CodeGen/LiveDebugValues.cpp
Expand Up @@ -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)};
}

Expand Down

0 comments on commit d64a22a

Please sign in to comment.