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 /gcc/testsuite | |
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 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/gdc.dg/asan/attr_no_sanitize1.d | 32 | ||||
-rw-r--r-- | gcc/testsuite/gdc.dg/ubsan/attr_no_sanitize2.d | 39 |
2 files changed, 71 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.dg/asan/attr_no_sanitize1.d b/gcc/testsuite/gdc.dg/asan/attr_no_sanitize1.d new file mode 100644 index 0000000..28908d4 --- /dev/null +++ b/gcc/testsuite/gdc.dg/asan/attr_no_sanitize1.d @@ -0,0 +1,32 @@ +// { dg-options "-fsanitize=address -O3 -fdump-tree-optimized" } +// { dg-do compile } + +import gcc.attributes; + +@no_sanitize("address") +__gshared int globalvar1; // { dg-warning "attribute ignored" } + +pragma(inline, true) +@no_sanitize("address") +void test_no_address() +{ + counter++; +} + +pragma(inline, true) +void test_sanitize()() +{ + counter++; +} + +void func1() +{ + counter++; + test_no_address(); + test_sanitize(); +} + +private int counter; + +// { dg-final { scan-tree-dump-times "Function test_no_address" 1 "optimized" } } +// { dg-final { scan-tree-dump-times "Function test_sanitize" 0 "optimized" } } diff --git a/gcc/testsuite/gdc.dg/ubsan/attr_no_sanitize2.d b/gcc/testsuite/gdc.dg/ubsan/attr_no_sanitize2.d new file mode 100644 index 0000000..c6e4784 --- /dev/null +++ b/gcc/testsuite/gdc.dg/ubsan/attr_no_sanitize2.d @@ -0,0 +1,39 @@ +// { dg-options "-fsanitize=undefined -O3 -fdump-tree-optimized" } +// { dg-do compile } + +import gcc.attributes; + +@no_sanitize("invalid_name") +void func1() { } // { dg-warning "attribute directive ignored" } + +@no_sanitize("address") +@no_sanitize("thread") +@no_sanitize("address,thread") +@no_sanitize("address", "undefined") +@no_sanitize("undefined", "leak", "return,null,bounds") +void func2() { } + +pragma(inline, true) +@no_sanitize("undefined") +void test_no_undefined()() +{ + counter++; +} + +pragma(inline, true) +void test_sanitize()() +{ + counter++; +} + +void func3() +{ + counter++; + test_no_undefined(); + test_sanitize(); +} + +private __gshared int counter; + +// { dg-final { scan-tree-dump-times "Function test_no_undefined" 1 "optimized" } } +// { dg-final { scan-tree-dump-times "Function test_sanitize" 0 "optimized" } } |