Skip to content

Commit 8dbc6b5

Browse files
committed
Revert "[randstruct] Check final randomized layout ordering"
This reverts commit a7815d3. Test fails on Windows, see comments on https://reviews.llvm.org/D124199
1 parent 494505f commit 8dbc6b5

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

clang/lib/AST/Randstruct.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ void randomizeStructureLayoutImpl(const ASTContext &Context,
150150
if (CurrentBitfieldRun)
151151
Buckets.push_back(std::move(CurrentBitfieldRun));
152152

153-
llvm::shuffle(std::begin(Buckets), std::end(Buckets), RNG);
153+
std::shuffle(std::begin(Buckets), std::end(Buckets), RNG);
154154

155155
// Produce the new ordering of the elements from the Buckets.
156156
SmallVector<FieldDecl *, 16> FinalOrder;
157157
for (const std::unique_ptr<Bucket> &B : Buckets) {
158158
llvm::SmallVectorImpl<FieldDecl *> &RandFields = B->fields();
159159
if (!B->isBitfieldRun())
160-
llvm::shuffle(std::begin(RandFields), std::end(RandFields), RNG);
160+
std::shuffle(std::begin(RandFields), std::end(RandFields), RNG);
161161

162162
FinalOrder.insert(FinalOrder.end(), RandFields.begin(), RandFields.end());
163163
}

clang/unittests/AST/RandstructTest.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ TEST(RANDSTRUCT_TEST, UnmarkedStruct) {
159159
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
160160

161161
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
162-
const field_names Expected = {"bacon", "lettuce", "tomato", "mayonnaise"};
163162

164-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
165163
EXPECT_FALSE(RD->hasAttr<RandomizeLayoutAttr>());
166164
EXPECT_FALSE(RD->isRandomized());
167165
}
@@ -179,9 +177,7 @@ TEST(RANDSTRUCT_TEST, MarkedNoRandomize) {
179177
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
180178

181179
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
182-
const field_names Expected = {"bacon", "lettuce", "tomato", "mayonnaise"};
183180

184-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
185181
EXPECT_TRUE(RD->hasAttr<NoRandomizeLayoutAttr>());
186182
EXPECT_FALSE(RD->isRandomized());
187183
}
@@ -199,9 +195,7 @@ TEST(RANDSTRUCT_TEST, MarkedRandomize) {
199195
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
200196

201197
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
202-
const field_names Expected = {"lettuce", "bacon", "mayonnaise", "tomato"};
203198

204-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
205199
EXPECT_TRUE(RD->hasAttr<RandomizeLayoutAttr>());
206200
EXPECT_TRUE(RD->isRandomized());
207201
}
@@ -215,7 +209,8 @@ TEST(RANDSTRUCT_TEST, MismatchedAttrsDeclVsDef) {
215209
long long tomato;
216210
float mayonnaise;
217211
} __attribute__((no_randomize_layout));
218-
)c", true);
212+
)c",
213+
true);
219214

220215
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
221216

@@ -236,7 +231,8 @@ TEST(RANDSTRUCT_TEST, MismatchedAttrsRandomizeVsNoRandomize) {
236231
long long tomato;
237232
float mayonnaise;
238233
} __attribute__((randomize_layout)) __attribute__((no_randomize_layout));
239-
)c", true);
234+
)c",
235+
true);
240236

241237
EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
242238

@@ -256,7 +252,8 @@ TEST(RANDSTRUCT_TEST, MismatchedAttrsNoRandomizeVsRandomize) {
256252
long long tomato;
257253
float mayonnaise;
258254
} __attribute__((no_randomize_layout)) __attribute__((randomize_layout));
259-
)c", true);
255+
)c",
256+
true);
260257

261258
EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
262259

@@ -283,16 +280,14 @@ TEST(RANDSTRUCT_TEST, CheckAdjacentBitfieldsRemainAdjacentAfterRandomization) {
283280
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
284281

285282
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
286-
const field_names Expected = {
287-
"a", "b", "c", "x", "y", "z" // x, y, z needs to be a subsequnce.
288-
};
283+
const field_names Actual = getFieldNamesFromRecord(RD);
284+
const field_names Subseq = {"x", "y", "z"};
289285

290-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
291286
EXPECT_TRUE(RD->isRandomized());
287+
EXPECT_TRUE(isSubsequence(Actual, Subseq));
292288
}
293289

294-
// FIXME: Enable when fix for flexible arrays is submitted.
295-
TEST(RANDSTRUCT_TEST, DISABLED_CheckVariableLengthArrayMemberRemainsAtEndOfStructure) {
290+
TEST(RANDSTRUCT_TEST, CheckVariableLengthArrayMemberRemainsAtEndOfStructure) {
296291
std::unique_ptr<ASTUnit> AST = makeAST(R"c(
297292
struct test {
298293
int a;
@@ -305,9 +300,7 @@ TEST(RANDSTRUCT_TEST, DISABLED_CheckVariableLengthArrayMemberRemainsAtEndOfStruc
305300
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
306301

307302
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
308-
const field_names Expected = {"c", "a", "b", "name"};
309303

310-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
311304
EXPECT_TRUE(RD->isRandomized());
312305
}
313306

@@ -332,7 +325,10 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
332325
long long b;
333326
int c[];
334327
} __attribute__((packed, randomize_layout));
335-
)c", false, field_names({"test_struct", "another_struct", "last_struct"}));
328+
)c",
329+
false,
330+
std::vector<std::string>(
331+
{"test_struct", "another_struct", "last_struct"}));
336332

337333
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
338334

@@ -344,9 +340,7 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
344340
getRecordDeclFromAST(AST->getASTContext(), "test_struct");
345341
const ASTRecordLayout *Layout =
346342
&AST->getASTContext().getASTRecordLayout(RD);
347-
const field_names Expected = {"b", "a", "c", "d"};
348343

349-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
350344
EXPECT_TRUE(RD->isRandomized());
351345
EXPECT_EQ(19, Layout->getSize().getQuantity());
352346
}
@@ -356,9 +350,7 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
356350
getRecordDeclFromAST(AST->getASTContext(), "another_struct");
357351
const ASTRecordLayout *Layout =
358352
&AST->getASTContext().getASTRecordLayout(RD);
359-
const field_names Expected = {"c", "b", "a"};
360353

361-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
362354
EXPECT_TRUE(RD->isRandomized());
363355
EXPECT_EQ(10, Layout->getSize().getQuantity());
364356
}
@@ -368,9 +360,7 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
368360
getRecordDeclFromAST(AST->getASTContext(), "last_struct");
369361
const ASTRecordLayout *Layout =
370362
&AST->getASTContext().getASTRecordLayout(RD);
371-
const field_names Expected = {"a", "c", "b"};
372363

373-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
374364
EXPECT_TRUE(RD->isRandomized());
375365
EXPECT_EQ(9, Layout->getSize().getQuantity());
376366
}
@@ -388,9 +378,7 @@ TEST(RANDSTRUCT_TEST, ZeroWidthBitfieldsSeparateAllocationUnits) {
388378
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
389379

390380
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
391-
const field_names Expected = {"a", "b", ""};
392381

393-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
394382
EXPECT_TRUE(RD->isRandomized());
395383
}
396384

@@ -408,10 +396,9 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotRandomizeUnionFieldOrder) {
408396

409397
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
410398

411-
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
412-
const field_names Expected = {"a", "b", "c", "d", "e", "f"};
399+
const RecordDecl *RD =
400+
getRecordDeclFromAST(AST->getASTContext(), "test");
413401

414-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
415402
EXPECT_FALSE(RD->isRandomized());
416403
}
417404

@@ -449,9 +436,7 @@ TEST(RANDSTRUCT_TEST, AnonymousStructsAndUnionsRetainFieldOrder) {
449436
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
450437

451438
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
452-
const field_names Expected = {"", "l", "", "r", "s", "a", "f"};
453439

454-
EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
455440
EXPECT_TRUE(RD->isRandomized());
456441

457442
bool AnonStructTested = false;

0 commit comments

Comments
 (0)