[PATCH] D124694: [randstruct] Move initializer check to be more effective

Bill Wendling via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 2 12:46:43 PDT 2022


void added a comment.

In D124694#3486547 <https://reviews.llvm.org/D124694#3486547>, @void wrote:

> In D124694#3485585 <https://reviews.llvm.org/D124694#3485585>, @aaron.ballman wrote:
>
>>   struct t {
>>      int a, b, c, d, e;
>>   } x = { .a = 2, 4, 5, 6 };
>>
>> This situation seems like it should be an error, shouldn't it? The user specified one designated initializer (yay, that one is correct), but the rest are positional initializers and so there's no telling what they actually initialize due to field randomization.
>
> That is diagnosed as an error. The issue is that after randomization, the `a` field is placed at the end of the structure. The initializer checker then sees the `.a = 2` and says, "Ah! That's the one at the end of the structure. Any non-designated initializers afterwards will be excess ones," which is what happens. But that warning is completely mysterious to the end users who isn't told that they can't have a non-designated initializer on a randomized structure. Moving the diagnostic allows the correct warning to be emitted instead of the "excess elements" one.

`s/is placed/may be places/`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124694



More information about the cfe-commits mailing list