Co-authored-by: Cole Nixon <nixontc...@gmail.com> Co-authored-by: Connor Kuehl <cipku...@gmail.com> Co-authored-by: James Foster <jafoste...@gmail.com> Co-authored-by: Jeff Takahashi <jeffrey.takaha...@gmail.com> Co-authored-by: Jordan Cantrell <jordan.cantr...@mail.com> Co-authored-by: Nikk Forbus <nicholas.for...@gmail.com> Co-authored-by: Tim Pugh <nwtp...@gmail.com> --- clang/lib/AST/RecordLayoutBuilder.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index 99b7cbd0224..4bdf467db4d 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/AST/RandstructSeed.h" #include "clang/AST/RecordLayout.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" @@ -15,6 +16,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" +#include "clang/AST/RecordFieldReorganizer.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/SmallSet.h" #include "llvm/Support/Format.h" @@ -2984,6 +2986,24 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const { const ASTRecordLayout *NewEntry = nullptr; + bool ShouldBeRandomized = D->getAttr<RandomizeLayoutAttr>() != nullptr; + bool NotToBeRandomized = D->getAttr<NoRandomizeLayoutAttr>() != nullptr; + bool AutoSelectable = RandstructAutoSelect && Randstruct::isTriviallyRandomizable(D); + + if (ShouldBeRandomized && NotToBeRandomized) { + getDiagnostics().Report(D->getLocation(), diag::warn_randomize_attr_conflict); + } + + if (ShouldBeRandomized && D->isUnion()) { + getDiagnostics().Report(D->getLocation(), diag::warn_randomize_attr_union); + NotToBeRandomized = true; + } + + if (!NotToBeRandomized && (ShouldBeRandomized || AutoSelectable)) { + Randstruct randstruct(RandstructSeed); + randstruct.reorganizeFields(*this,D); + } + if (isMsLayout(*this)) { MicrosoftRecordLayoutBuilder Builder(*this); if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) { -- 2.17.1 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits