mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 07:31:28 +00:00
[clangd] Fix a hover crash on unsigned 64bit value
This patch adapts to D140059, which makes an assumption that the caller of `APSInt::getExtValue` promises no narrowing conversion happens, i.e., from unsigned int64 to signed int64. It also fixes clangd/clangd#1557. Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D146874
This commit is contained in:
parent
12e8463b14
commit
0b103edf5b
@ -400,9 +400,9 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
|
||||
// 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);
|
||||
|
@ -3045,6 +3045,15 @@ TEST(Hover, NoCrash) {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user