From d64a22a2add97ff1ae28acb18c9f6ea76a26ecf3 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 2 Mar 2020 16:56:17 -0800 Subject: [PATCH] [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)]; ... ``` --- llvm/lib/CodeGen/LiveDebugValues.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp index ad54378d9edc..4d0c2462b7d3 100644 --- a/llvm/lib/CodeGen/LiveDebugValues.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues.cpp @@ -138,7 +138,10 @@ struct LocIndex { return (static_cast(Location) << 32) | Index; } - static LocIndex fromRawInteger(uint64_t ID) { + template static LocIndex fromRawInteger(IntT ID) { + static_assert(std::is_unsigned::value && + sizeof(ID) == sizeof(uint64_t), + "Cannot convert raw integer to LocIndex"); return {static_cast(ID >> 32), static_cast(ID)}; }