zyounan created this revision. Herald added subscribers: kadircet, arphaman. Herald added a project: All. zyounan requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
This patch adapts to D140059 <https://reviews.llvm.org/D140059>, which makes an assumption that the caller of `APSInt::getExtValue` promises no narrowing conversion happens, i.e., from signed int64 to unsigned int64. It also fixes clangd/clangd#1557. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D146874 Files: clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2947,6 +2947,15 @@ getHover(AST, P, format::getLLVMStyle(), nullptr); } +TEST(Hover, NoCrashAPInt64) { + Annotations T(R"cpp( + constexpr unsigned long value = -1; // wrap around + void foo() { va$1^lue; } + )cpp"); + auto AST = TestTU::withCode(T.code()).build(); + getHover(AST, T.point("1"), format::getLLVMStyle(), nullptr); +} + TEST(Hover, DocsFromMostSpecial) { Annotations T(R"cpp( // doc1 Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -395,7 +395,7 @@ // -2 => 0xfffffffe // -2^32 => 0xfffffffeffffffff static llvm::FormattedNumber printHex(const llvm::APSInt &V) { - uint64_t Bits = V.getExtValue(); + uint64_t Bits = V.getZExtValue(); if (V.isNegative() && V.getSignificantBits() <= 32) return llvm::format_hex(uint32_t(Bits), 0); return llvm::format_hex(Bits, 0);
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2947,6 +2947,15 @@ getHover(AST, P, format::getLLVMStyle(), nullptr); } +TEST(Hover, NoCrashAPInt64) { + Annotations T(R"cpp( + constexpr unsigned long value = -1; // wrap around + void foo() { va$1^lue; } + )cpp"); + auto AST = TestTU::withCode(T.code()).build(); + getHover(AST, T.point("1"), format::getLLVMStyle(), nullptr); +} + TEST(Hover, DocsFromMostSpecial) { Annotations T(R"cpp( // doc1 Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -395,7 +395,7 @@ // -2 => 0xfffffffe // -2^32 => 0xfffffffeffffffff static llvm::FormattedNumber printHex(const llvm::APSInt &V) { - uint64_t Bits = V.getExtValue(); + uint64_t Bits = V.getZExtValue(); if (V.isNegative() && V.getSignificantBits() <= 32) return llvm::format_hex(uint32_t(Bits), 0); return llvm::format_hex(Bits, 0);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits