[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 12:47:04 PDT 2023
erichkeane 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:
>
> ```c++
> 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 Would you still prefer restricting type argument to integral and enumeration types?
I think that is the least dangerous, but the `requireCompleteType` isn't awful (and I can do a disagree & commit on). I think it gets goofy when the sizes don't match with floating point/complex/etc, but I also see "you got what you asked for!" as being a reasonable defense to that.
https://github.com/llvm/llvm-project/pull/69104
More information about the cfe-commits
mailing list