File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1919#include " llvm/Support/Format.h"
2020#include " llvm/Support/MathExtras.h"
2121
22+ #include < algorithm>
23+ #include < random>
24+
2225using namespace clang ;
2326
2427namespace {
@@ -1362,14 +1365,27 @@ void ItaniumRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
13621365 bool InsertExtraPadding = D->mayInsertExtraPadding (/* EmitRemark=*/ true );
13631366 bool HasFlexibleArrayMember = D->hasFlexibleArrayMember ();
13641367
1368+ // A staging area to easily reorder the fields
1369+ SmallVector<Decl *, 64 > fields;
1370+ for (auto f : D->fields ()) {
1371+ fields.push_back (f);
1372+ }
1373+
13651374 bool ShouldBeRandomized = D->getAttr <RandomizeLayoutAttr>() != nullptr ;
13661375 if (ShouldBeRandomized) {
1367- llvm::outs () << D->getNameAsString () << " \n " ;
1376+ // FIXME Should call our Randstruct code once we port it.
1377+ auto rng = std::default_random_engine {};
1378+ std::shuffle (std::begin (fields), std::end (fields), rng);
1379+
1380+ // This will rebuild the Decl chain of fields
1381+ D->reorderFields (fields);
13681382 }
13691383
1384+
13701385 for (auto I = D->field_begin (), End = D->field_end (); I != End; ++I) {
13711386 auto Next (I);
13721387 ++Next;
1388+
13731389 LayoutField (*I,
13741390 InsertExtraPadding && (Next != End || !HasFlexibleArrayMember));
13751391 }
You can’t perform that action at this time.
0 commit comments