aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.dg
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-06-15 22:51:52 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2022-06-15 23:16:21 +0200
commit90f2a111413a6d4264335046d68ffa19725864b6 (patch)
tree566e5fee798421401ae158412b179351a25e7c52 /gcc/testsuite/gdc.dg
parentdc9b92facf87a6f2d8b0e5d5fc404f30c3b15a74 (diff)
downloadgcc-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/gdc.dg')
-rw-r--r--gcc/testsuite/gdc.dg/asan/attr_no_sanitize1.d32
-rw-r--r--gcc/testsuite/gdc.dg/ubsan/attr_no_sanitize2.d39
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" } }