Skip to content

Commit 9949798

Browse files
committed
Docs for the single attribute, 'randomize_layout'.
1 parent 09a54e9 commit 9949798

File tree

3 files changed

+5
-43
lines changed

3 files changed

+5
-43
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,12 +3206,5 @@ def RandomizeLayout : InheritableAttr {
32063206
let Spellings = [GCC<"randomize_layout">, Declspec<"randomize_layout">,
32073207
Keyword<"randomize_layout">];
32083208
let Subjects = SubjectList<[Record]>;
3209-
let Documentation = [Undocumented];
3210-
}
3211-
3212-
def NoRandomizeLayout : InheritableAttr {
3213-
let Spellings = [GCC<"no_randomize_layout">, Declspec<"no_randomize_layout">,
3214-
Keyword<"no_randomize_layout">];
3215-
let Subjects = SubjectList<[Record]>;
3216-
let Documentation = [Undocumented];
3209+
let Documentation = [ClangRandstructDocs];
32173210
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,24 +4099,11 @@ When compiled without ``-fobjc-arc``, this attribute is ignored.
40994099

41004100
def ClangRandstructDocs : Documentation {
41014101
let Category = DocCatVariable;
4102-
let Heading = "randomize_layout, no_randomize_layout";
4102+
let Heading = "randomize_layout;
41034103
let Content = [{
4104-
The attributes ``randomize_layout`` and ``no_randomize_layout`` can be applied
4105-
to a record.
4106-
4107-
``randomize_layout`` instructs the compiler to randomize the memory layout
4104+
The attribute ``randomize_layout`` can be applied to the declaration of
4105+
a record. ``randomize_layout`` instructs the compiler to randomize the memory layout
41084106
of the member variables of the record.
4109-
4110-
Conversely, ``no_randomize_layout`` is used to indicate that if using the
4111-
automatic strucuture selection feature of the Randstruct implementation, the
4112-
compiler should not shuffle the members of the record.
4113-
4114-
In the event that a record is labeled with both attributes, the compiler will
4115-
emit a warning indicating that these two cannot be used on the same record.
4116-
The default behavior in this case is to not randomize the struct, as the
4117-
attribute ``no_randomize_layout`` takes precedence over ``randomize_layout``.
4118-
This is implementation defined behavior.
4119-
41204107
.. code-block:: c
41214108

41224109
// Indicates that this struct should be randomized by Randstruct implementation.
@@ -4125,19 +4112,5 @@ This is implementation defined behavior.
41254112
char *b;
41264113
char *c;
41274114
}__attribute__((randomize_layout));
4128-
4129-
// Indicates that this struct should NOT be randomized by Randstruct implementation.
4130-
struct s {
4131-
char *a;
4132-
char *b;
4133-
char *c;
4134-
}__attribute__((no_randomize_layout));
4135-
4136-
// Emits compiler warning. Struct is NOT randomized by Randstruct implementation.
4137-
struct s {
4138-
char *a;
4139-
char *b;
4140-
char *c;
4141-
}__attribute__((randomize_layout)) __attribute__((no_randomize_layout));
41424115
}];
41434116
}

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,12 +2988,8 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
29882988
const ASTRecordLayout *NewEntry = nullptr;
29892989

29902990
bool ShouldBeRandomized = D->getAttr<RandomizeLayoutAttr>() != nullptr;
2991-
bool NotToBeRandomized = D->getAttr<NoRandomizeLayoutAttr>() != nullptr;
29922991

2993-
if (ShouldBeRandomized && NotToBeRandomized) {
2994-
getDiagnostics().Report(D->getLocation(), diag::warn_randomize_attr_conflict);
2995-
}
2996-
else if (ShouldBeRandomized) {
2992+
if (ShouldBeRandomized) {
29972993
Randstruct randstruct;
29982994
randstruct.reorganizeFields(*this,D);
29992995
}

0 commit comments

Comments
 (0)