summarylogtreecommitdiffstats
path: root/hover-bit-fields-mask.patch
blob: e9fadd765b78642c4d1fe1e7401619ed98745f0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index 0ec85fc24df1..40528784e775 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1011,9 +1011,17 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
     if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
       const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
       HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
-      if (FD->isBitField())
+      if (FD->isBitField()) {
         HI.Size = FD->getBitWidthValue(Ctx);
-      else if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType()))
+        if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) {
+          const auto SizeInBytes = Size->getQuantity();
+          const auto TypeOffset = *HI.Offset - (*HI.Offset % (SizeInBytes * 8));
+          HI.Value = llvm::utohexstr(
+              (~(std::numeric_limits<uint64_t>::max() << *HI.Size))
+                  << (*HI.Offset - TypeOffset),
+              true, SizeInBytes * 2);
+        }
+      } else if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType()))
         HI.Size = FD->isZeroSize(Ctx) ? 0 : Size->getQuantity() * 8;
       if (HI.Size) {
         unsigned EndOfField = *HI.Offset + *HI.Size;