diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-15 22:51:52 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-15 23:16:21 +0200 |
commit | 90f2a111413a6d4264335046d68ffa19725864b6 (patch) | |
tree | 566e5fee798421401ae158412b179351a25e7c52 /libphobos/libdruntime/gcc | |
parent | dc9b92facf87a6f2d8b0e5d5fc404f30c3b15a74 (diff) | |
download | gcc-90f2a111413a6d4264335046d68ffa19725864b6.zip gcc-90f2a111413a6d4264335046d68ffa19725864b6.tar.gz gcc-90f2a111413a6d4264335046d68ffa19725864b6.tar.bz2 |
d: Add `@no_sanitize' attribute to compiler and library.
The `@no_sanitize' attribute disables a particular sanitizer for this
function, analogous to `__attribute__((no_sanitize))'. The library also
defines `@noSanitize' to be compatible with the LLVM D compiler's
`ldc.attributes'.
gcc/d/ChangeLog:
* d-attribs.cc (d_langhook_attribute_table): Add no_sanitize.
(d_handle_no_sanitize_attribute): New function.
libphobos/ChangeLog:
* libdruntime/gcc/attributes.d (no_sanitize): Define.
(noSanitize): Define.
gcc/testsuite/ChangeLog:
* gdc.dg/asan/attr_no_sanitize1.d: New test.
* gdc.dg/ubsan/attr_no_sanitize2.d: New test.
Diffstat (limited to 'libphobos/libdruntime/gcc')
-rw-r--r-- | libphobos/libdruntime/gcc/attributes.d | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libphobos/libdruntime/gcc/attributes.d b/libphobos/libdruntime/gcc/attributes.d index ca066ce..710e8ab 100644 --- a/libphobos/libdruntime/gcc/attributes.d +++ b/libphobos/libdruntime/gcc/attributes.d @@ -182,6 +182,33 @@ enum flatten = attribute("flatten"); enum no_icf = attribute("no_icf"); /** + * The `@no_sanitize` attribute on functions is used to inform the compiler + * that it should not do sanitization of any option mentioned in + * sanitize_option. A list of values acceptable by the `-fsanitize` option + * can be provided. + * + * Example: + * --- + * import gcc.attributes; + * + * @no_sanitize("alignment", "object-size") void func1() { } + * @no_sanitize("alignment,object-size") void func2() { } + * --- + */ + +auto no_sanitize(A...)(A arguments) + if (allSatisfy!(isStringValue, arguments)) +{ + return attribute("no_sanitize", arguments); +} + +auto no_sanitize(A...)(A arguments) + if (!allSatisfy!(isStringValue, arguments)) +{ + assert(false, "no_sanitize attribute argument not a string constant"); +} + +/** * The `@noclone` attribute prevents a function from being considered for * cloning - a mechanism that produces specialized copies of functions and * which is (currently) performed by interprocedural constant propagation. @@ -595,6 +622,14 @@ enum hidden = visibility("hidden"); enum naked = attribute("naked"); /** + * Disables a particular sanitizer for this function. + * Valid sanitizer names are all names accepted by `-fsanitize=` commandline option. + * Multiple sanitizers can be disabled by applying this UDA multiple times, e.g. + * `@noSanitize("address") `@noSanitize("thread")` to disable both ASan and TSan. + */ +alias noSanitize = no_sanitize; + +/** * Sets the optimization strategy for a function. * Valid strategies are "none", "optsize", "minsize". The strategies are * mutually exclusive. |