[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 10:20:06 PDT 2022


aaron.ballman added a comment.

In D122248#3405644 <https://reviews.llvm.org/D122248#3405644>, @yihanaa wrote:

> In D122248#3405166 <https://reviews.llvm.org/D122248#3405166>, @erichkeane wrote:
>
>> In D122248#3405062 <https://reviews.llvm.org/D122248#3405062>, @aaron.ballman wrote:
>>
>>> In D122248#3403734 <https://reviews.llvm.org/D122248#3403734>, @yihanaa wrote:
>>>
>>>> What if we don't emit '=' for zero-width bitfield, like this:
>>>>
>>>>   struct Bar {
>>>>   unsigned c : 1;
>>>>   unsigned : 3;
>>>>   unsigned : 0;
>>>>   unsigned b;
>>>>   };
>>>>   
>>>>   struct Bar {
>>>>   unsigned int c : 1 = 0
>>>>   unsigned int   : 3 = 0
>>>>   unsigned int   : 0
>>>>   unsigned int b = 0
>>>>   }
>>>>
>>>> What do you all think?
>>>
>>> I like this idea best of all!
>>
>> Agreed!
>
> @erichkeane @aaron.ballman 
> Previously we used FieldDecl->getNameAsString to get the field name, but the comments for this function indicate that it is Deprecated,and suggestion move clients to getName().
>
> The FieldDecl->getName() return the anonymous inner struct's name like:
>
>   struct T3A {
>     union {
>       int a;
>       char b[4];
>     };
>   };
>
>   struct T3A {
>   union T3A::(anonymous at ./builtin_dump_struct.c:77:5) {
>       int a = 42
>       char[4] b = 0x2a
>       }
>   }
>
> what do you all think?

I would probably keep using `getNameAsString()` as I don't think the extra information helps overly much. That interface was marked deprecated 13 years ago, so don't feel bad for making use of it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248



More information about the cfe-commits mailing list