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

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 23 11:53:41 PDT 2022


erichkeane added a comment.

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

> In D122248#3403315 <https://reviews.llvm.org/D122248#3403315>, @aaron.ballman wrote:
>
>> In D122248#3403143 <https://reviews.llvm.org/D122248#3403143>, @yihanaa wrote:
>>
>>> 1. Support zero-width bitfield, named bitfield and unnamed bitfield.
>>> 2. Add a release notes.
>>>
>>> The builtin function __builtin_dump_struct behaves for zero-width bitfield and unnamed bitfield as follows
>>>
>>>   int printf(const char *fmt, ...);
>>>   
>>>   void foo(void) {
>>>     struct Bar {
>>>       unsigned c : 1;
>>>       unsigned : 3;
>>>       unsigned : 0;
>>>       unsigned b;
>>>     };
>>>   
>>>     struct Bar a = {
>>>       .c = 1,
>>>       .b = 2022,
>>>     };
>>>   
>>>     __builtin_dump_struct(&a, &printf);
>>>   }
>>>   
>>>   int main() {
>>>     foo();
>>>     return 0;
>>>   }
>>>
>>> Output:
>>>
>>>   struct Bar {
>>>   unsigned int c : 1
>>>   unsigned int  : 0
>>>   unsigned int b : 2022
>>>   }
>>
>> Thank you for the release note and additional test coverage. I'm wondering why we handle the zero-width bit-field differently from the anonymous one (e.g., why do we not have `unsigned int : 3` before the `unsigned int : 0`? It seems a bit odd to drop that from the output.
>
> Thanks, I don't know what the value of this zero-width bitfield should output, can it be a empty value as same as unnamed-bitfield’ she field name?
>
> for example:
>
>   struct Bar {
>   unsigned int c : 1
>   unsigned int  : 0
>   unsigned int  :
>   unsigned int b : 2022
>   }

I would definitely expect this, yes.


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