[PATCH] D146874: [clangd] Fix a hover crash on unsigned 64bit value
Younan Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 26 05:04:39 PDT 2023
zyounan updated this revision to Diff 508401.
zyounan marked an inline comment as done.
zyounan added a comment.
Address comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146874/new/
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^lue; }
+ )cpp");
+ auto AST = TestTU::withCode(T.code()).build();
+ getHover(AST, T.point(), 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
@@ -393,9 +393,9 @@
// 100 => 0x64
// Negative numbers are sign-extended to 32/64 bits
// -2 => 0xfffffffe
-// -2^32 => 0xfffffffeffffffff
+// -2^32 => 0xffffffff00000000
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146874.508401.patch
Type: text/x-patch
Size: 1300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230326/246ec3df/attachment.bin>
More information about the cfe-commits
mailing list