[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 09:43:25 PDT 2023


Endilll wrote:

> However, will this actually work in practice in the debugger? If not, perhaps we should limit to just integer and enumeration types for now, leaving the extension for the future.

I composed an example of that:
```cpp
struct A {
  short a1;
  short a2;
};

struct B {
  [[clang::preferred_type(A)]] unsigned b1 : 32 = 0x000F'000C;
};

int main()
{
    B b;
    return b.b1;
}
```
Nightly build of LLDB from apt.llvm.org handles it just fine:
```
Process 2755547 stopped
* thread #1, name = 'test-preferred-', stop reason = step in
    frame #0: 0x0000555555555148 test-preferred-type`main at test.cxx:13:14
   10   int main()
   11   {
   12       B b;
-> 13       return b.b1;
   14   }
(lldb) v -T
(B) b = {
  (A:32) b1 = {
    (short) a1 = 12
    (short) a2 = 15
  }
}
```
@erichkeane Do you still insist on restricting type argument to integral and enumeration types?

https://github.com/llvm/llvm-project/pull/69104


More information about the cfe-commits mailing list