aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMaxim Ostapenko <chefmax@gcc.gnu.org>2014-10-28 14:40:00 +0200
committerMaxim Ostapenko <chefmax@gcc.gnu.org>2014-10-28 14:40:00 +0200
commitacc770ae3be0824167b80217d67e34d00ae868fe (patch)
tree87aac893be9b155474e565e2b0dc07ec4911db78 /gcc
parentbdea98ca2e2c29d1ad4c124c4a7c0d23c3330920 (diff)
downloadgcc-acc770ae3be0824167b80217d67e34d00ae868fe.zip
gcc-acc770ae3be0824167b80217d67e34d00ae868fe.tar.gz
gcc-acc770ae3be0824167b80217d67e34d00ae868fe.tar.bz2
Add missing tests.
From-SVN: r216785
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-10.c18
-rw-r--r--gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-11.c20
-rw-r--r--gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-12.c16
-rw-r--r--gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-13.c15
-rw-r--r--gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-14.c15
-rw-r--r--gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-15.c16
-rw-r--r--gcc/testsuite/c-c++-common/asan/pr63638.c20
7 files changed, 120 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-10.c b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-10.c
new file mode 100644
index 0000000..24dfcfe
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-10.c
@@ -0,0 +1,18 @@
+/* { dg-options "-fdump-tree-sanopt" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
+
+extern __UINT32_TYPE__ a;
+
+void
+foo ()
+{
+ /* Instrument a with access size 3. */
+ int d = __builtin_memcmp (&a, "123", 3);
+ /* This should generate a __builtin___asan_report_store4, because
+ the reference to a has been instrumented above with access size 3. */
+ a = 1;
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store4" 1 "sanopt" } } */
+/* { dg-final { cleanup-tree-dump "sanopt" } } */
diff --git a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-11.c b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-11.c
new file mode 100644
index 0000000..4082f32
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-11.c
@@ -0,0 +1,20 @@
+/* { dg-options "-fdump-tree-sanopt" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
+
+extern __UINT32_TYPE__ a;
+
+void
+foo ()
+{
+ /* Instrument a with access size 5. */
+ int d = __builtin_memcmp (&a, "12345", 4);
+ /* This should not generate a __builtin___asan_report_store4 because
+ the reference to a has been already instrumented above with access
+ size 5. */
+ a = 1;
+}
+
+/* { dg-final { scan-tree-dump-not "& 7" "sanopt" } } */
+/* { dg-final { scan-tree-dump-not "__builtin___asan_report_store" "sanopt" } } */
+/* { dg-final { cleanup-tree-dump "sanopt" } } */
diff --git a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-12.c b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-12.c
new file mode 100644
index 0000000..65e1d96
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-12.c
@@ -0,0 +1,16 @@
+/* { dg-options "-fdump-tree-sanopt" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+void
+foo (char *p)
+{
+ volatile int zero = 0;
+ __builtin_memcpy (p, "abc", zero);
+ /* This generates a __builtin___asan_report_store1 because we pass volatile
+ zero length into memcpy. */
+ p[0] = 'd';
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 1 "sanopt" } } */
+/* { dg-final { cleanup-tree-dump "sanopt" } } */
diff --git a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-13.c b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-13.c
new file mode 100644
index 0000000..c04be06
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-13.c
@@ -0,0 +1,15 @@
+/* { dg-options "-fdump-tree-sanopt" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
+
+void
+foo (char *p)
+{
+ __builtin_memcpy (p, "abc", 0);
+ /* This generates a __builtin___asan_report_store1 because we didn't access
+ any byte in previous memcpy because of zero length parameter. */
+ p[0] = 'd';
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 1 "sanopt" } } */
+/* { dg-final { cleanup-tree-dump "sanopt" } } */
diff --git a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-14.c b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-14.c
new file mode 100644
index 0000000..fadce90
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-14.c
@@ -0,0 +1,15 @@
+/* { dg-options "-fdump-tree-sanopt" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
+
+void
+foo (char *p)
+{
+ __builtin_memcpy (p, "abc", 2);
+ /* This doesn't generate a __builtin___asan_report_store1 because we
+ verified p[0] through p[2] is writable in previous memcpy call. */
+ p[0] = 'd';
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin___asan_report_store1" "sanopt" } } */
+/* { dg-final { cleanup-tree-dump "sanopt" } } */
diff --git a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-15.c b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-15.c
new file mode 100644
index 0000000..00676da
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-15.c
@@ -0,0 +1,16 @@
+/* { dg-options "-fdump-tree-sanopt" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+void
+foo (char *p)
+{
+ volatile int two = 2;
+ __builtin_memcpy (p, "abc", two);
+ /* This generates a __builtin___asan_report_store1 because we don't
+ optimize previous memcpy call. */
+ p[0] = 'd';
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 1 "sanopt" } } */
+/* { dg-final { cleanup-tree-dump "sanopt" } } */
diff --git a/gcc/testsuite/c-c++-common/asan/pr63638.c b/gcc/testsuite/c-c++-common/asan/pr63638.c
new file mode 100644
index 0000000..a8bafc5
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/pr63638.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void *memcpy (void *, const void *, __SIZE_TYPE__);
+
+struct S{
+ long d0, d1, d2, d3, d4, d5, d6;
+};
+
+struct S s[6];
+
+int f(struct S *p)
+{
+ memcpy(p, &s[2], sizeof(*p));
+ memcpy(p, &s[1], sizeof(*p));
+}
+