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 19
19
#include " llvm/Support/Format.h"
20
20
#include " llvm/Support/MathExtras.h"
21
21
22
+ #include < algorithm>
23
+ #include < random>
24
+
22
25
using namespace clang ;
23
26
24
27
namespace {
@@ -1362,14 +1365,27 @@ void ItaniumRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
1362
1365
bool InsertExtraPadding = D->mayInsertExtraPadding (/* EmitRemark=*/ true );
1363
1366
bool HasFlexibleArrayMember = D->hasFlexibleArrayMember ();
1364
1367
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
+
1365
1374
bool ShouldBeRandomized = D->getAttr <RandomizeLayoutAttr>() != nullptr ;
1366
1375
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);
1368
1382
}
1369
1383
1384
+
1370
1385
for (auto I = D->field_begin (), End = D->field_end (); I != End; ++I) {
1371
1386
auto Next (I);
1372
1387
++Next;
1388
+
1373
1389
LayoutField (*I,
1374
1390
InsertExtraPadding && (Next != End || !HasFlexibleArrayMember));
1375
1391
}
You can’t perform that action at this time.
0 commit comments