[PATCH] D59254: [RFC] Implementation of Clang randstruct

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 24 04:35:46 PDT 2019


On Tue, Jul 23, 2019 at 9:17 PM Connor Kuehl via Phabricator
<reviews at reviews.llvm.org> wrote:
>
> connorkuehl added a comment.
>
> In D59254#1429401 <https://reviews.llvm.org/D59254#1429401>, @jfb wrote:
>
> > I find it easier to understand the code by looking at the tests. When you add tests, please make sure you test for:
> >
> > - Bit-fields
> > - Zero-width bit-field
>
>
> Hi JF,
>
> Could you elaborate on what I should be testing for here regarding the zero-width bit-field? I'm not sure zero-width bit-fields are a concern since I think they're illegal. I just tried compiling a "hello world" program with a struct that has a zero width bit-field as one of its members and the compiler emitted an error pointing at it.
>
>   error: named bit-field 'z' has zero width
>           int z : 0;
>               ^
>   1 error generated.

Zero-width bit-fields are not illegal, but they must be unnamed. e.g.,

struct S {
  int a : 1;
  int : 0;
  int b : 1;
};

See C17 6.7.2.1p12 for more details about zero-width bit-fields, but
essentially, the above declaration will pack a and b into separate
allocation units.

~Aaron

>
> For regular bit-fields the current implementation will keep adjacent bit-fields together and will preserve their original order but the overall group of adjacent bit-fields may relocate. My next revision will have a unit test describing and testing this behavior.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D59254/new/
>
> https://reviews.llvm.org/D59254
>
>
>


More information about the cfe-commits mailing list