[PATCH] D123958: [randstruct] Randomize all elements of a record

Bill Wendling via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 19 23:06:22 PDT 2022


void added a comment.

In D123958#3459205 <https://reviews.llvm.org/D123958#3459205>, @aaron.ballman wrote:

> I think you'll need a more targeted approach than assuming the only kinds of declarations in a struct are field-like in C.
>
> It seems that the issue you've got is with anonymous objects in a structure where the inner fields are available for lookup in the outer structure. One question I have is: what's the expectation for the user? There's two ways to look at this. 1) The anonymous object is a single field; that its members can be found in the outer object is not relevant. 2) The fields of the anonymous object should also be randomized. The same is true for any inner structure, not just anonymous ones.
>
> I had assumed that any structure not marked for randomization would not be randomized. Based on that, I don't think inner structure objects (anonymous or otherwise) should automatically randomize their fields. WDYT?

We don't randomize inner structures unless they have the `randomize_layout` flag. That's always been the case, and this patch doesn't change that.

The issue is that we were dropping the inner structures/unions because they aren't `FieldDecl`s, but `RecordDecl`s, with an `IndirectFieldDecl` if the inner structure is anonymous. The `IndirectFieldDecl` bits appear after the `RecordDecl` they're attached to, but doesn't seem like the ordering is important. The `IndirectFieldDecl` thing is there so that the anonymous fields are available in the outer structure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123958



More information about the cfe-commits mailing list