File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -343,4 +343,10 @@ def warn_padded_struct_size : Warning<
343
343
InGroup<Padded>, DefaultIgnore;
344
344
def warn_unnecessary_packed : Warning<
345
345
"packed attribute is unnecessary for %0">, InGroup<Packed>, DefaultIgnore;
346
+
347
+ // RandStruct implementation
348
+ def warn_randomize_attr_conflict : Warning<
349
+ "struct declared with 'randomize_layout' and 'no_randomize_layout' attributes. "
350
+ "attribute 'no_randomize_layout' takes precedence ">;
351
+
346
352
}
Original file line number Diff line number Diff line change @@ -2986,11 +2986,27 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
2986
2986
if (Entry) return *Entry;
2987
2987
2988
2988
const ASTRecordLayout *NewEntry = nullptr ;
2989
-
2989
+
2990
2990
bool ShouldBeRandomized = D->getAttr <RandomizeLayoutAttr>() != nullptr ;
2991
2991
if (ShouldBeRandomized) {
2992
2992
Randstruct randstruct;
2993
2993
randstruct.reorganizeFields (*this , D);
2994
+ bool NotToBeRandomized = D->getAttr <NoRandomizeLayoutAttr>() != nullptr ;
2995
+
2996
+ if (ShouldBeRandomized && NotToBeRandomized) {
2997
+ Diag (D->getLocation (), diag::warn_randomize_attr_conflict);
2998
+ }
2999
+ else if (ShouldBeRandomized) {
3000
+ // A staging area to easily reorder the fields
3001
+ SmallVector<Decl *, 64 > fields;
3002
+ for (auto f : D->fields ()) {
3003
+ fields.push_back (f);
3004
+ }
3005
+
3006
+ fields = rearrange (*this , fields);
3007
+
3008
+ // This will rebuild the Decl chain of fields
3009
+ D->reorderFields (fields);
2994
3010
}
2995
3011
2996
3012
if (isMsLayout (*this )) {
You can’t perform that action at this time.
0 commit comments