Skip to content

Commit fe25c0e

Browse files
committed
Skip Unions when selecting from randomization
There's no harmful effect if we DO randomize a union, however, since all of a union's data members have their offsets set to 0 there's no advantage for our code to run anyway. This way we can spare some CPU cycles in the event that someone adds the randomize attribute to their union.
1 parent d95e624 commit fe25c0e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,7 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
29902990

29912991
bool ShouldBeRandomized = D->getAttr<RandomizeLayoutAttr>() != nullptr;
29922992

2993-
if (ShouldBeRandomized) {
2993+
if (ShouldBeRandomized && !D->isUnion()) {
29942994
Randstruct randstruct;
29952995
randstruct.reorganizeFields(*this,D);
29962996
}

0 commit comments

Comments
 (0)