[randstruct] Randomize all elements of a record
authorBill Wendling <isanbard@gmail.com>
Thu, 28 Apr 2022 19:00:47 +0000 (12:00 -0700)
committerBill Wendling <isanbard@gmail.com>
Thu, 28 Apr 2022 19:01:11 +0000 (12:01 -0700)
commit463790bfc70e15f9c23b76f1c53e228b644f8bb1
tree3bcf5f18c6f3eb41170c1ad33c56f36e9850c0aa
parentce6bfd102af5d3431ff19f322fce27e033a34c49
[randstruct] Randomize all elements of a record

A record may have more than just FieldDecls in it. If so, then we're
likely to drop them if we only randomize the FieldDecls.

We need to be careful about anonymous structs/unions. Their fields are
made available in the RecordDecl as IndirectFieldDecls, which are listed
after the anonymous struct/union. The ordering doesn't appear to be
super important, however we place them unrandomized at the end of the
RecordDecl just in case. There's also the possiblity of
StaticAssertDecls. We also want those at the end.

All other non-FieldDecls we place at the top, just in case we get
something like:

    struct foo {
      enum e { BORK };
      enum e a;
    };

Link: https://github.com/KSPP/linux/issues/185
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D123958
clang/include/clang/AST/Decl.h
clang/include/clang/AST/Randstruct.h
clang/lib/AST/Decl.cpp
clang/lib/AST/Randstruct.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/Sema/init-randomized-struct.c
clang/unittests/AST/RandstructTest.cpp