[clang-tools-extra] [clangd] Fix crash on hover over 64bit enums with MSB set (PR #173187)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 20 19:31:14 PDT 2026
================
@@ -454,19 +455,28 @@ std::optional<std::string> printExprValue(const Expr *E,
return std::nullopt;
// Show enums symbolically, not numerically like APValue::printPretty().
- if (T->isEnumeralType() && Constant.Val.isInt() &&
- Constant.Val.getInt().getSignificantBits() <= 64) {
- // Compare to int64_t to avoid bit-width match requirements.
- int64_t Val = Constant.Val.getInt().getExtValue();
- for (const EnumConstantDecl *ECD : T->castAsEnumDecl()->enumerators())
- if (ECD->getInitVal() == Val)
- return llvm::formatv("{0} ({1})", ECD->getNameAsString(),
- printHex(Constant.Val.getInt()))
- .str();
+ if (T->isEnumeralType() && Constant.Val.isInt()) {
+ const llvm::APSInt &Val = Constant.Val.getInt();
+ if (Val.isRepresentableByInt64()) {
+ // Compare to int64_t to avoid bit-width match requirements.
+ int64_t Val = Constant.Val.getInt().getExtValue();
+ for (const EnumConstantDecl *ECD : T->castAsEnumDecl()->enumerators())
+ if (ECD->getInitVal() == Val)
+ return llvm::formatv("{0} ({1})", ECD->getNameAsString(),
----------------
timon-ul wrote:
Uhm, maybe I am going insane, now I get the same as you, but I swear earlier I was getting `Value = 42 (0x2a)` printed when hovering over `var`....makes sense though to print its actual name, had me confused. I also have seen that `getName()` is the new replacement, but since I got a number I thought `getName()` would then fail.
Anyway I would then suggest moving this call to `getName()`.
https://github.com/llvm/llvm-project/pull/173187
More information about the cfe-commits
mailing list