diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/asan')
-rw-r--r-- | gcc/testsuite/g++.dg/asan/function-argument-1.C | 31 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asan/function-argument-2.C | 24 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asan/function-argument-3.C | 28 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asan/pr81021.C | 33 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asan/pr81340.C | 22 |
5 files changed, 138 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/asan/function-argument-1.C b/gcc/testsuite/g++.dg/asan/function-argument-1.C new file mode 100644 index 00000000000..bdbb37a44a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/function-argument-1.C @@ -0,0 +1,31 @@ +// { dg-do run } +// { dg-shouldfail "asan" } +// { dg-options "-fsanitize=address -fno-sanitize-address-use-after-scope" } + +struct A +{ + int a[5]; +}; + +static __attribute__ ((noinline)) int +goo (A *a) +{ + int *ptr = &a->a[0]; + return *(volatile int *) (ptr - 1); +} + +__attribute__ ((noinline)) int +foo (A arg) +{ + return goo (&arg); +} + +int +main () +{ + return foo (A ()); +} + +// { dg-output "ERROR: AddressSanitizer: stack-buffer-underflow on address.*(\n|\r\n|\r)" } +// { dg-output "READ of size . at.*" } +// { dg-output ".*'arg' <== Memory access at offset \[0-9\]* underflows this variable.*" } diff --git a/gcc/testsuite/g++.dg/asan/function-argument-2.C b/gcc/testsuite/g++.dg/asan/function-argument-2.C new file mode 100644 index 00000000000..3a7c33bdaaa --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/function-argument-2.C @@ -0,0 +1,24 @@ +// { dg-do run } +// { dg-shouldfail "asan" } + +static __attribute__ ((noinline)) int +goo (int *a) +{ + return *(volatile int *)a; +} + +__attribute__ ((noinline)) int +foo (char arg) +{ + return goo ((int *)&arg); +} + +int +main () +{ + return foo (12); +} + +// { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow on address.*(\n|\r\n|\r)" } +// { dg-output "READ of size . at.*" } +// { dg-output ".*'arg' <== Memory access at offset \[0-9\]* partially overflows this variable.*" } diff --git a/gcc/testsuite/g++.dg/asan/function-argument-3.C b/gcc/testsuite/g++.dg/asan/function-argument-3.C new file mode 100644 index 00000000000..6994b6df1c8 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/function-argument-3.C @@ -0,0 +1,28 @@ +// { dg-do run } +// { dg-shouldfail "asan" } +// { dg-additional-options "-Wno-psabi" } + +typedef int v4si __attribute__ ((vector_size (16))); + +static __attribute__ ((noinline)) int +goo (v4si *a) +{ + return (*(volatile v4si *) (a + 1))[2]; +} + +__attribute__ ((noinline)) int +foo (v4si arg) +{ + return goo (&arg); +} + +int +main () +{ + v4si v = {1,2,3,4}; + return foo (v); +} + +// { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow on address.*(\n|\r\n|\r)" } +// { dg-output "READ of size . at.*" } +// { dg-output ".*'arg' <== Memory access at offset \[0-9\]* overflows this variable.*" } diff --git a/gcc/testsuite/g++.dg/asan/pr81021.C b/gcc/testsuite/g++.dg/asan/pr81021.C new file mode 100644 index 00000000000..daa0525c273 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/pr81021.C @@ -0,0 +1,33 @@ +// { dg-do run } + +#include <string> + +struct ConfigFile { + ConfigFile(std::string filename, std::string delimiter) { throw "error"; } + ConfigFile(std::string filename) {} +}; + +struct Configuration { + ConfigFile _configFile; + + Configuration(const std::string &root, const char *baseName) + : _configFile(root + baseName, "=") { } + Configuration(const std::string &root, const char *a, const char *b) + : _configFile(root + a + b) { } +}; + + +void test() { + std::string root("etc"); + try { + Configuration config(root, "notthere"); + } + catch (...) { + // exception is thrown, caught here and ignored... + } + Configuration config(root, "a", "b"); // ASAN error during constructor here +} + +int main(int argc, const char *argv[]) { + test(); +} diff --git a/gcc/testsuite/g++.dg/asan/pr81340.C b/gcc/testsuite/g++.dg/asan/pr81340.C new file mode 100644 index 00000000000..76ac08a9a56 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/pr81340.C @@ -0,0 +1,22 @@ +// { dg-options "-fsanitize=address -O2 -g -Wno-write-strings" } + +class a { + struct b { + b(int, int); + } c; + +public: + int d; + a(char *) : c(0, d) {} +}; +class e { + int f(const int &, const int &, const int &, bool, bool, bool, int, bool); +}; +class g { +public: + static g *h(); + void i(a, void *); +}; +int e::f(const int &, const int &, const int &, bool j, bool, bool, int, bool) { + g::h()->i("", &j); +} |