@@ -159,9 +159,7 @@ TEST(RANDSTRUCT_TEST, UnmarkedStruct) {
159
159
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
160
160
161
161
const RecordDecl *RD = getRecordDeclFromAST (AST->getASTContext (), " test" );
162
- const field_names Expected = {" bacon" , " lettuce" , " tomato" , " mayonnaise" };
163
162
164
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
165
163
EXPECT_FALSE (RD->hasAttr <RandomizeLayoutAttr>());
166
164
EXPECT_FALSE (RD->isRandomized ());
167
165
}
@@ -179,9 +177,7 @@ TEST(RANDSTRUCT_TEST, MarkedNoRandomize) {
179
177
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
180
178
181
179
const RecordDecl *RD = getRecordDeclFromAST (AST->getASTContext (), " test" );
182
- const field_names Expected = {" bacon" , " lettuce" , " tomato" , " mayonnaise" };
183
180
184
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
185
181
EXPECT_TRUE (RD->hasAttr <NoRandomizeLayoutAttr>());
186
182
EXPECT_FALSE (RD->isRandomized ());
187
183
}
@@ -199,9 +195,7 @@ TEST(RANDSTRUCT_TEST, MarkedRandomize) {
199
195
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
200
196
201
197
const RecordDecl *RD = getRecordDeclFromAST (AST->getASTContext (), " test" );
202
- const field_names Expected = {" lettuce" , " bacon" , " mayonnaise" , " tomato" };
203
198
204
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
205
199
EXPECT_TRUE (RD->hasAttr <RandomizeLayoutAttr>());
206
200
EXPECT_TRUE (RD->isRandomized ());
207
201
}
@@ -215,7 +209,8 @@ TEST(RANDSTRUCT_TEST, MismatchedAttrsDeclVsDef) {
215
209
long long tomato;
216
210
float mayonnaise;
217
211
} __attribute__((no_randomize_layout));
218
- )c" , true );
212
+ )c" ,
213
+ true );
219
214
220
215
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
221
216
@@ -236,7 +231,8 @@ TEST(RANDSTRUCT_TEST, MismatchedAttrsRandomizeVsNoRandomize) {
236
231
long long tomato;
237
232
float mayonnaise;
238
233
} __attribute__((randomize_layout)) __attribute__((no_randomize_layout));
239
- )c" , true );
234
+ )c" ,
235
+ true );
240
236
241
237
EXPECT_TRUE (AST->getDiagnostics ().hasErrorOccurred ());
242
238
@@ -256,7 +252,8 @@ TEST(RANDSTRUCT_TEST, MismatchedAttrsNoRandomizeVsRandomize) {
256
252
long long tomato;
257
253
float mayonnaise;
258
254
} __attribute__((no_randomize_layout)) __attribute__((randomize_layout));
259
- )c" , true );
255
+ )c" ,
256
+ true );
260
257
261
258
EXPECT_TRUE (AST->getDiagnostics ().hasErrorOccurred ());
262
259
@@ -283,16 +280,14 @@ TEST(RANDSTRUCT_TEST, CheckAdjacentBitfieldsRemainAdjacentAfterRandomization) {
283
280
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
284
281
285
282
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" };
289
285
290
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
291
286
EXPECT_TRUE (RD->isRandomized ());
287
+ EXPECT_TRUE (isSubsequence (Actual, Subseq));
292
288
}
293
289
294
- // FIXME: Enable when fix for flexible arrays is submitted.
295
- TEST (RANDSTRUCT_TEST, DISABLED_CheckVariableLengthArrayMemberRemainsAtEndOfStructure) {
290
+ TEST (RANDSTRUCT_TEST, CheckVariableLengthArrayMemberRemainsAtEndOfStructure) {
296
291
std::unique_ptr<ASTUnit> AST = makeAST (R"c(
297
292
struct test {
298
293
int a;
@@ -305,9 +300,7 @@ TEST(RANDSTRUCT_TEST, DISABLED_CheckVariableLengthArrayMemberRemainsAtEndOfStruc
305
300
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
306
301
307
302
const RecordDecl *RD = getRecordDeclFromAST (AST->getASTContext (), " test" );
308
- const field_names Expected = {" c" , " a" , " b" , " name" };
309
303
310
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
311
304
EXPECT_TRUE (RD->isRandomized ());
312
305
}
313
306
@@ -332,7 +325,10 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
332
325
long long b;
333
326
int c[];
334
327
} __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" }));
336
332
337
333
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
338
334
@@ -344,9 +340,7 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
344
340
getRecordDeclFromAST (AST->getASTContext (), " test_struct" );
345
341
const ASTRecordLayout *Layout =
346
342
&AST->getASTContext ().getASTRecordLayout (RD);
347
- const field_names Expected = {" b" , " a" , " c" , " d" };
348
343
349
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
350
344
EXPECT_TRUE (RD->isRandomized ());
351
345
EXPECT_EQ (19 , Layout->getSize ().getQuantity ());
352
346
}
@@ -356,9 +350,7 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
356
350
getRecordDeclFromAST (AST->getASTContext (), " another_struct" );
357
351
const ASTRecordLayout *Layout =
358
352
&AST->getASTContext ().getASTRecordLayout (RD);
359
- const field_names Expected = {" c" , " b" , " a" };
360
353
361
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
362
354
EXPECT_TRUE (RD->isRandomized ());
363
355
EXPECT_EQ (10 , Layout->getSize ().getQuantity ());
364
356
}
@@ -368,9 +360,7 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotOverrideThePackedAttr) {
368
360
getRecordDeclFromAST (AST->getASTContext (), " last_struct" );
369
361
const ASTRecordLayout *Layout =
370
362
&AST->getASTContext ().getASTRecordLayout (RD);
371
- const field_names Expected = {" a" , " c" , " b" };
372
363
373
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
374
364
EXPECT_TRUE (RD->isRandomized ());
375
365
EXPECT_EQ (9 , Layout->getSize ().getQuantity ());
376
366
}
@@ -388,9 +378,7 @@ TEST(RANDSTRUCT_TEST, ZeroWidthBitfieldsSeparateAllocationUnits) {
388
378
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
389
379
390
380
const RecordDecl *RD = getRecordDeclFromAST (AST->getASTContext (), " test" );
391
- const field_names Expected = {" a" , " b" , " " };
392
381
393
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
394
382
EXPECT_TRUE (RD->isRandomized ());
395
383
}
396
384
@@ -408,10 +396,9 @@ TEST(RANDSTRUCT_TEST, RandstructDoesNotRandomizeUnionFieldOrder) {
408
396
409
397
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
410
398
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 " ) ;
413
401
414
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
415
402
EXPECT_FALSE (RD->isRandomized ());
416
403
}
417
404
@@ -449,9 +436,7 @@ TEST(RANDSTRUCT_TEST, AnonymousStructsAndUnionsRetainFieldOrder) {
449
436
EXPECT_FALSE (AST->getDiagnostics ().hasErrorOccurred ());
450
437
451
438
const RecordDecl *RD = getRecordDeclFromAST (AST->getASTContext (), " test" );
452
- const field_names Expected = {" " , " l" , " " , " r" , " s" , " a" , " f" };
453
439
454
- EXPECT_EQ (Expected, getFieldNamesFromRecord (RD));
455
440
EXPECT_TRUE (RD->isRandomized ());
456
441
457
442
bool AnonStructTested = false ;
0 commit comments