Skip to content

Commit 7272914

Browse files
committed
First draft for attribute documentation
1 parent ae1bf92 commit 7272914

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4094,4 +4094,52 @@ Likewise, when applied to a strong local variable, that variable becomes
40944094
``const`` and is considered externally-retained.
40954095

40964096
When compiled without ``-fobjc-arc``, this attribute is ignored.
4097-
}]; }
4097+
}];
4098+
}
4099+
4100+
def ClangRandstructDocs : Documentation {
4101+
let Category = DocCatVariable;
4102+
let Heading = "randomize_layout, no_randomize_layout";
4103+
let Content = [{
4104+
The attributes ``randomize_layout`` and ``no_randomize_layout`` can be applied
4105+
to a C struct or class(???).
4106+
4107+
``randomize_layout`` instructs the compiler to randomize the memory location
4108+
of the member variables of the struct or class(???). Functions will not be
4109+
shuffled, unless in the event that the member is a function pointer, then it
4110+
will be shuffled as a normal member variable.
4111+
4112+
Conversely, ``no_randomize_layout`` is used to indicate that if using the
4113+
Automatic Strucuture Selection feature of the Randstruct implementation, the
4114+
compiler should not shuffle the members of the struct.
4115+
4116+
If in the event that a struct or class(???) is labeled with both attributes,
4117+
the compiler will emit a warning indicating that these two cannot be used on
4118+
the same struct of class(???). The default behavior in this case is to not
4119+
randomize the struct, as the attribute ``no_randomize_layout`` takes precedence
4120+
over ``randomize_layout``.
4121+
4122+
.. code-block:: c
4123+
4124+
// Indicates that this struct should be randomized by Randstruct implementation.
4125+
struct __attribute__((randomize_layout)) s {
4126+
char *a;
4127+
char *b;
4128+
char *c;
4129+
};
4130+
4131+
// Indicates that this struct should NOT be randomized by Randstruct implementation.
4132+
struct __attribute__((no_randomize_layout)) s {
4133+
char *a;
4134+
char *b;
4135+
char *c;
4136+
};
4137+
4138+
// Emits compiler warning. Struct is NOT randomized by Randstruct implementation.
4139+
struct __attribute__((randomize_layout)) __attribute__((no_randomize_layout)) s {
4140+
char *a;
4141+
char *b;
4142+
char *c;
4143+
};
4144+
}];
4145+
}

0 commit comments

Comments
 (0)