aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveDebugValues.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2020-03-02 16:56:17 -0800
committerVedant Kumar <vsk@apple.com>2020-03-02 16:59:09 -0800
commitd64a22a2add97ff1ae28acb18c9f6ea76a26ecf3 (patch)
tree442ade2b52db01fec3ed7780922bd0c6eb215ab7 /llvm/lib/CodeGen/LiveDebugValues.cpp
parent29a4239d31c6d8ccc557afbe0999aa096ca95cc6 (diff)
downloadllvm-d64a22a2add97ff1ae28acb18c9f6ea76a26ecf3.zip
llvm-d64a22a2add97ff1ae28acb18c9f6ea76a26ecf3.tar.gz
llvm-d64a22a2add97ff1ae28acb18c9f6ea76a26ecf3.tar.bz2
[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)]; ... ```
Diffstat (limited to 'llvm/lib/CodeGen/LiveDebugValues.cpp')
-rw-r--r--llvm/lib/CodeGen/LiveDebugValues.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp
index ad54378..4d0c246 100644
--- a/llvm/lib/CodeGen/LiveDebugValues.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues.cpp
@@ -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)};
}