[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-08-06 Thread SR_team via Phabricator via cfe-commits
SR_team added a comment.

Until a 10, we don't have difference between DEC and HEX, may be print only DEC 
in these cases?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157205/new/

https://reviews.llvm.org/D157205

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151128: [clangd] Show size, offset and padding for bit fields on hover

2023-06-05 Thread SR_team via Phabricator via cfe-commits
SR_team updated this revision to Diff 528458.
SR_team added a comment.

- moved lambda `FormatSize` to static function `formatSize()`;
- extracted offset format code to static function `formatOffset()`;
- always shows bytes in offset (for offset 4 showed `Offset: 0 bytes and 4 
bits`)
- added render test for bit-fields

> Let me know if you have commit access or I should land this for you (in which 
> case: please provide a preferred name/email for attribution)

Land it for me, please. Name: SR_team, email: m...@sr.team


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151128/new/

https://reviews.llvm.org/D151128

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  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
@@ -89,8 +89,8 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
- HI.Padding = 7;
+ HI.Size = 8;
+ HI.Padding = 56;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -107,8 +107,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
- HI.Size = 1;
- HI.Padding = 15;
+ HI.Size = 8;
+ HI.Padding = 120;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -125,6 +125,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.Offset = 0;
+ HI.Size = 1;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -188,7 +190,7 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
+ HI.Size = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -200,7 +202,7 @@
  HI.Name = "X";
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
- HI.Size = 1;
+ HI.Size = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1285,6 +1287,26 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "m_int arr[Size]";
  HI.Type = {"m_int[Size]", "int[Size]"};
+   }},
+  {// Bitfield offset, size and padding
+   R"cpp(
+struct Foo {
+  char x;
+  char [[^y]] : 1;
+  int z;
+};
+  )cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "y";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "char y : 1";
+ HI.Type = "char";
+ HI.Offset = 8;
+ HI.Size = 1;
+ HI.Padding = 23;
+ HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Code);
@@ -1508,7 +1530,7 @@
   {"auto s = ^[[\"Hello, world!\"]]; // string literal",
[](HoverInfo ) {
  HI.Name = "string-literal";
- HI.Size = 14;
+ HI.Size = 112;
  HI.Type = "const char[14]";
}},
   {
@@ -3218,7 +3240,7 @@
   {
   [](HoverInfo ) {
 HI.Kind = index::SymbolKind::Class;
-HI.Size = 10;
+HI.Size = 80;
 HI.TemplateParameters = {
 {{"typename"}, std::string("T"), std::nullopt},
 {{"typename"}, std::string("C"), std::string("bool")},
@@ -3274,16 +3296,38 @@
 HI.Name = "foo";
 HI.Type = {"type", "can_type"};
 HI.Definition = "def";
-HI.Size = 4;
-HI.Offset = 12;
-HI.Padding = 4;
+HI.Size = 32;
+HI.Offset = 96;
+HI.Padding = 32;
   },
   R"(field foo
 
 Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
-Size: 4 bytes (+4 padding)
+Size: 4 bytes (+4 bytes padding)
+
+// In test::Bar
+def)",
+  },
+  {
+  [](HoverInfo ) {
+HI.Kind = index::SymbolKind::Field;
+HI.LocalScope = "test::Bar::";
+HI.Value = "value";
+HI.Name = "foo";
+HI.Type = {"type", "can_type"};
+HI.Definition = "def";
+HI.Size = 25;
+HI.Offset = 35;
+HI.Padding = 4;
+  },
+  R"(field foo
+
+Type: type (aka can_type)
+Value = value
+Offset: 4 bytes and 3 bits
+Size: 25 bits (+4 bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -91,7 +91,7 @@
   std::optional> 

[PATCH] D151128: [clangd] Show size, offset and padding for bit fields on hover

2023-05-27 Thread SR_team via Phabricator via cfe-commits
SR_team added a comment.

@sammccall review my code please


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151128/new/

https://reviews.llvm.org/D151128

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151128: [clangd] Show size, offset and padding for bit fields on hover

2023-05-23 Thread SR_team via Phabricator via cfe-commits
SR_team updated this revision to Diff 524946.
SR_team added a comment.

Extract formatting to lambda, for simplify code modification


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151128/new/

https://reviews.llvm.org/D151128

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  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
@@ -89,8 +89,8 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
- HI.Padding = 7;
+ HI.Size = 8;
+ HI.Padding = 56;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -107,8 +107,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
- HI.Size = 1;
- HI.Padding = 15;
+ HI.Size = 8;
+ HI.Padding = 120;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -125,6 +125,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.Offset = 0;
+ HI.Size = 1;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -188,7 +190,7 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
+ HI.Size = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -200,7 +202,7 @@
  HI.Name = "X";
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
- HI.Size = 1;
+ HI.Size = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1285,6 +1287,26 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "m_int arr[Size]";
  HI.Type = {"m_int[Size]", "int[Size]"};
+   }},
+  {// Bitfield offset, size and padding
+   R"cpp(
+struct Foo {
+  char x;
+  char [[^y]] : 1;
+  int z;
+};
+  )cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "y";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "char y : 1";
+ HI.Type = "char";
+ HI.Offset = 8;
+ HI.Size = 1;
+ HI.Padding = 23;
+ HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Code);
@@ -1508,7 +1530,7 @@
   {"auto s = ^[[\"Hello, world!\"]]; // string literal",
[](HoverInfo ) {
  HI.Name = "string-literal";
- HI.Size = 14;
+ HI.Size = 112;
  HI.Type = "const char[14]";
}},
   {
@@ -3218,7 +3240,7 @@
   {
   [](HoverInfo ) {
 HI.Kind = index::SymbolKind::Class;
-HI.Size = 10;
+HI.Size = 80;
 HI.TemplateParameters = {
 {{"typename"}, std::string("T"), std::nullopt},
 {{"typename"}, std::string("C"), std::string("bool")},
@@ -3274,16 +3296,16 @@
 HI.Name = "foo";
 HI.Type = {"type", "can_type"};
 HI.Definition = "def";
-HI.Size = 4;
-HI.Offset = 12;
-HI.Padding = 4;
+HI.Size = 32;
+HI.Offset = 96;
+HI.Padding = 32;
   },
   R"(field foo
 
 Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
-Size: 4 bytes (+4 padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -91,7 +91,7 @@
   std::optional> TemplateParameters;
   /// Contains the evaluated value of the symbol if available.
   std::optional Value;
-  /// Contains the byte-size of fields and types where it's interesting.
+  /// Contains the bit-size of fields and types where it's interesting.
   std::optional Size;
   /// Contains the offset of fields within the enclosing class.
   std::optional Offset;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -866,7 +866,7 @@
   HoverInfo HI;
 
   HI.Name = "string-literal";
-  HI.Size = (SL->getLength() + 1) * SL->getCharByteWidth();
+  HI.Size = (SL->getLength() + 1) * SL->getCharByteWidth() * 8;
   HI.Type = SL->getType().getAsString(PP).c_str();
 
   return HI;
@@ -1000,7 +1000,7 @@
   const auto  = ND.getASTContext();
   if (auto *RD = llvm::dyn_cast()) {
 if (auto Size = 

[PATCH] D151128: [clangd] Show size, offset and padding for bit fields on hover

2023-05-23 Thread SR_team via Phabricator via cfe-commits
SR_team updated this revision to Diff 524938.
SR_team added a comment.

Stores `Offset`, `Size` and `Padding` fields of HoverInfo in bits. When hover 
present bits converted to bytes, if possible.

Examle:

  struct test {
char a;
char b : 3;
char c : 5;
int d;
int e : 31;
  };

F27617774: image.png 
F27617776: image.png 
F2761: image.png 
F27617780: image.png 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151128/new/

https://reviews.llvm.org/D151128

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  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
@@ -89,8 +89,8 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
- HI.Padding = 7;
+ HI.Size = 8;
+ HI.Padding = 56;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -107,8 +107,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
- HI.Size = 1;
- HI.Padding = 15;
+ HI.Size = 8;
+ HI.Padding = 120;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -125,6 +125,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.Offset = 0;
+ HI.Size = 1;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -188,7 +190,7 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
+ HI.Size = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -200,7 +202,7 @@
  HI.Name = "X";
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
- HI.Size = 1;
+ HI.Size = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1285,6 +1287,26 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "m_int arr[Size]";
  HI.Type = {"m_int[Size]", "int[Size]"};
+   }},
+  {// Bitfield offset, size and padding
+   R"cpp(
+struct Foo {
+  char x;
+  char [[^y]] : 1;
+  int z;
+};
+  )cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "y";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "char y : 1";
+ HI.Type = "char";
+ HI.Offset = 8;
+ HI.Size = 1;
+ HI.Padding = 23;
+ HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Code);
@@ -1508,7 +1530,7 @@
   {"auto s = ^[[\"Hello, world!\"]]; // string literal",
[](HoverInfo ) {
  HI.Name = "string-literal";
- HI.Size = 14;
+ HI.Size = 112;
  HI.Type = "const char[14]";
}},
   {
@@ -3218,7 +3240,7 @@
   {
   [](HoverInfo ) {
 HI.Kind = index::SymbolKind::Class;
-HI.Size = 10;
+HI.Size = 80;
 HI.TemplateParameters = {
 {{"typename"}, std::string("T"), std::nullopt},
 {{"typename"}, std::string("C"), std::string("bool")},
@@ -3274,16 +3296,16 @@
 HI.Name = "foo";
 HI.Type = {"type", "can_type"};
 HI.Definition = "def";
-HI.Size = 4;
-HI.Offset = 12;
-HI.Padding = 4;
+HI.Size = 32;
+HI.Offset = 96;
+HI.Padding = 32;
   },
   R"(field foo
 
 Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
-Size: 4 bytes (+4 padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -91,7 +91,7 @@
   std::optional> TemplateParameters;
   /// Contains the evaluated value of the symbol if available.
   std::optional Value;
-  /// Contains the byte-size of fields and types where it's interesting.
+  /// Contains the bit-size of fields and types where it's interesting.
   std::optional Size;
   /// Contains the offset of fields within the enclosing class.
   std::optional Offset;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ 

[PATCH] D151128: [clangd] Show size, offset and padding for bit fields on hover

2023-05-23 Thread SR_team via Phabricator via cfe-commits
SR_team updated this revision to Diff 524933.
SR_team added a comment.

Stores `Offset`, `Size` and `Padding` fields of HoverInfo in bits. When hover 
present bits converted to bytes, if possible.

Examle:

  struct test {
char a;
char b : 3;
char c : 5;
int d;
  };

F27617664: image.png 
F27617668: image.png 
F27617673: image.png 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151128/new/

https://reviews.llvm.org/D151128

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  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
@@ -89,8 +89,8 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
- HI.Padding = 7;
+ HI.Size = 8;
+ HI.Padding = 56;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -107,8 +107,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
- HI.Size = 1;
- HI.Padding = 15;
+ HI.Size = 8;
+ HI.Padding = 120;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -125,6 +125,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.Offset = 0;
+ HI.Size = 1;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -188,7 +190,7 @@
  HI.Definition = "char bar";
  HI.Type = "char";
  HI.Offset = 0;
- HI.Size = 1;
+ HI.Size = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -200,7 +202,7 @@
  HI.Name = "X";
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
- HI.Size = 1;
+ HI.Size = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1285,6 +1287,26 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "m_int arr[Size]";
  HI.Type = {"m_int[Size]", "int[Size]"};
+   }},
+  {// Bitfield offset, size and padding
+   R"cpp(
+struct Foo {
+  char x;
+  char [[^y]] : 1;
+  int z;
+};
+  )cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "y";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "char y : 1";
+ HI.Type = "char";
+ HI.Offset = 8;
+ HI.Size = 1;
+ HI.Padding = 23;
+ HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Code);
@@ -1508,7 +1530,7 @@
   {"auto s = ^[[\"Hello, world!\"]]; // string literal",
[](HoverInfo ) {
  HI.Name = "string-literal";
- HI.Size = 14;
+ HI.Size = 112;
  HI.Type = "const char[14]";
}},
   {
@@ -3218,7 +3240,7 @@
   {
   [](HoverInfo ) {
 HI.Kind = index::SymbolKind::Class;
-HI.Size = 10;
+HI.Size = 80;
 HI.TemplateParameters = {
 {{"typename"}, std::string("T"), std::nullopt},
 {{"typename"}, std::string("C"), std::string("bool")},
@@ -3274,16 +3296,16 @@
 HI.Name = "foo";
 HI.Type = {"type", "can_type"};
 HI.Definition = "def";
-HI.Size = 4;
-HI.Offset = 12;
-HI.Padding = 4;
+HI.Size = 32;
+HI.Offset = 96;
+HI.Padding = 32;
   },
   R"(field foo
 
 Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
-Size: 4 bytes (+4 padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -91,7 +91,7 @@
   std::optional> TemplateParameters;
   /// Contains the evaluated value of the symbol if available.
   std::optional Value;
-  /// Contains the byte-size of fields and types where it's interesting.
+  /// Contains the bit-size of fields and types where it's interesting.
   std::optional Size;
   /// Contains the offset of fields within the enclosing class.
   std::optional Offset;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -866,7 +866,7 @@
   HoverInfo HI;
 
   HI.Name 

[PATCH] D151128: [clangd] Show size, offset and padding for bit fields on hover

2023-05-23 Thread SR_team via Phabricator via cfe-commits
SR_team added a comment.

In D151128#4365218 , @sammccall wrote:

> I do see the appeal of making this work for bitfields, but I think silently 
> rounding offset/size/padding to whole bytes is pretty misleading.
> For bitfields we'd really need to talk about layout at a bit level.
> But we don't want to talk about regular fields in bits (I think?!)
> And having a mixture seems like it's going to be pretty complicated both in 
> implementation and for users, for a smallish feature.
>
> I don't see a great sweet-spot design, maybe you/others have ideas (or can 
> explain why the rounding behavior in this patch is reasonable.

We can store this fields in bits, and show in bytes on hover, when it's 
possible, and in bits, when showing in bytes impossible. Would such an 
implementation be good?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151128/new/

https://reviews.llvm.org/D151128

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151128: [clangd] Show size, offset and padding for bit fields on hover

2023-05-22 Thread SR_team via Phabricator via cfe-commits
SR_team created this revision.
SR_team added a reviewer: sammccall.
SR_team added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
SR_team requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

In some cases, we want to view the bytes offset of a bit field block, like in:

  struct SomeFlags{
// ~32 named bit flags, before foo
bool foo : 1;
   // ~ 31 named bit flags, after foo
  };

With this diff in hover showed offset for `foo` in bytes. This offset is 
floored (e.g. offset 9 bits floored to 8 bits and convert to bytes).
Size of bit fields is ceiled to convert in bytes (e.g. 9 bits ceiled to 16 
bits).

Logic to calculate padding not changed, so it showed for floored bits (e.g. 9 
bits floored to 8 bits and present as 1 byte)


https://reviews.llvm.org/D151128

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
@@ -125,6 +125,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.Offset = 0;
+ HI.Size = 1;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -1285,6 +1287,26 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "m_int arr[Size]";
  HI.Type = {"m_int[Size]", "int[Size]"};
+   }},
+  {// Bitfield offset, size and padding
+   R"cpp(
+struct Foo {
+  char x;
+  char [[^y]] : 1;
+  int z;
+};
+  )cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "y";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "char y : 1";
+ HI.Type = "char";
+ HI.Offset = 1;
+ HI.Size = 1;
+ HI.Padding = 2;
+ HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1008,12 +1008,15 @@
 const auto *Record = FD->getParent();
 if (Record)
   Record = Record->getDefinition();
-if (Record && !Record->isInvalidDecl() && !Record->isDependentType() &&
-!FD->isBitField()) {
+if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
   const ASTRecordLayout  = Ctx.getASTRecordLayout(Record);
   HI.Offset = Layout.getFieldOffset(FD->getFieldIndex()) / 8;
-  if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) {
+  if (FD->isBitField()) {
+const auto SizeInBits = FD->getBitWidthValue(Ctx);
+HI.Size = (SizeInBits + 7) >> 3;
+  } else if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType()))
 HI.Size = FD->isZeroSize(Ctx) ? 0 : Size->getQuantity();
+  if (HI.Size) {
 unsigned EndOfField = *HI.Offset + *HI.Size;
 
 // Calculate padding following the field.


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -125,6 +125,8 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.Offset = 0;
+ HI.Size = 1;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -1285,6 +1287,26 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "m_int arr[Size]";
  HI.Type = {"m_int[Size]", "int[Size]"};
+   }},
+  {// Bitfield offset, size and padding
+   R"cpp(
+struct Foo {
+  char x;
+  char [[^y]] : 1;
+  int z;
+};
+  )cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "y";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "char y : 1";
+ HI.Type = "char";
+ HI.Offset = 1;
+ HI.Size = 1;
+ HI.Padding = 2;
+ HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1008,12 +1008,15 @@
 const auto *Record = FD->getParent();
 if (Record)
   Record = Record->getDefinition();
-if 

[PATCH] D125224: [CodeComplete] prototype of contextual postfix completions

2023-04-23 Thread SR_team via Phabricator via cfe-commits
SR_team added a comment.

Iterator checks may crash in current state. Also, `pointeeType` may return 
invalid type of iterator store (`T*` instead of `T`)




Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5589
+  const auto  =
+  static_cast(RD->getDeclContext())
+  ->getTemplateArgs();

RD is nullptr here - use `RT->getDecl()->getDeclContext()` instead



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5646
+  if (!Element.isNull()) {
+if (Element->isPointerType())
+  return "const auto*";

GNU STL use pointer to type in iterators, so need check is `Element` 
pointer-to-pointer:
```
if (Element->isPointerType()) {
  if (const auto *PT = dyn_cast(Element)) {
Element = PT->getPointeeType();
if (Element->isPointerType())
  return "const auto*";
  }
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125224/new/

https://reviews.llvm.org/D125224

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits