[compiler-rt] 2554619 - [ASAN] Restore and adjust tests
Dávid Bolvanský via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 18 08:28:44 PDT 2020
Author: Dávid Bolvanský
Date: 2020-10-18T17:28:05+02:00
New Revision: 2554619adbc8a8856c39b93bc049a5b4a4895cc5
URL: https://github.com/llvm/llvm-project/commit/2554619adbc8a8856c39b93bc049a5b4a4895cc5
DIFF: https://github.com/llvm/llvm-project/commit/2554619adbc8a8856c39b93bc049a5b4a4895cc5.diff
LOG: [ASAN] Restore and adjust tests
There are optimized out with -fno-builtin
Added:
compiler-rt/test/asan/TestCases/strcat-overlap.cpp
compiler-rt/test/asan/TestCases/strcpy-overlap.cpp
compiler-rt/test/asan/TestCases/strncat-overlap.cpp
compiler-rt/test/asan/TestCases/strncpy-overlap.cpp
Modified:
Removed:
################################################################################
diff --git a/compiler-rt/test/asan/TestCases/strcat-overlap.cpp b/compiler-rt/test/asan/TestCases/strcat-overlap.cpp
new file mode 100644
index 000000000000..c9b11babaf87
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/strcat-overlap.cpp
@@ -0,0 +1,54 @@
+// RUN: %clangxx_asan -O0 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O1 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O2 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O3 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+
+// This test when run with suppressions invokes undefined
+// behavior which can cause all sorts of bad things to happen
+// depending on how strcat() is implemented. For now only run
+// on platforms where we know the test passes.
+// REQUIRES: x86_64h-darwin || x86_64-darwin || i386-darwin || x86_64-linux || i386-linux
+// UNSUPPORTED: windows-msvc
+// UNSUPPORTED: android
+
+#include <string.h>
+
+
+// Don't inline function otherwise stacktrace changes.
+__attribute__((noinline)) void bad_function() {
+ char buffer[] = "hello\0XXX";
+ // CHECK: strcat-param-overlap: memory ranges
+ // CHECK: [{{0x.*,[ ]*0x.*}}) and [{{0x.*,[ ]*0x.*}}) overlap
+ // CHECK: {{#0 0x.* in .*strcat}}
+ // CHECK: {{#1 0x.* in bad_function.*strcat-overlap.cpp:}}[[@LINE+2]]
+ // CHECK: {{#2 0x.* in main .*strcat-overlap.cpp:}}[[@LINE+5]]
+ strcat(buffer, buffer + 1); // BOOM
+}
+
+int main(int argc, char **argv) {
+ bad_function();
+ return 0;
+}
\ No newline at end of file
diff --git a/compiler-rt/test/asan/TestCases/strcpy-overlap.cpp b/compiler-rt/test/asan/TestCases/strcpy-overlap.cpp
new file mode 100644
index 000000000000..eefea67b8da8
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/strcpy-overlap.cpp
@@ -0,0 +1,48 @@
+// RUN: %clangxx_asan -O0 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O1 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O2 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O3 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strcpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+
+// UNSUPPORTED: android
+
+#include <string.h>
+
+
+// Don't inline function otherwise stacktrace changes.
+__attribute__((noinline)) void bad_function() {
+ char buffer[] = "hello";
+ // CHECK: strcpy-param-overlap: memory ranges
+ // CHECK: [{{0x.*,[ ]*0x.*}}) and [{{0x.*,[ ]*0x.*}}) overlap
+ // CHECK: {{#0 0x.* in .*strcpy}}
+ // CHECK: {{#1 0x.* in bad_function.*strcpy-overlap.cpp:}}[[@LINE+2]]
+ // CHECK: {{#2 0x.* in main .*strcpy-overlap.cpp:}}[[@LINE+5]]
+ strcpy(buffer, buffer + 1); // BOOM
+}
+
+int main(int argc, char **argv) {
+ bad_function();
+ return 0;
+}
\ No newline at end of file
diff --git a/compiler-rt/test/asan/TestCases/strncat-overlap.cpp b/compiler-rt/test/asan/TestCases/strncat-overlap.cpp
new file mode 100644
index 000000000000..d454b81fbff6
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/strncat-overlap.cpp
@@ -0,0 +1,48 @@
+// RUN: %clangxx_asan -O0 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O1 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O2 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O3 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncat" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+
+// UNSUPPORTED: android
+
+#include <string.h>
+
+
+// Don't inline function otherwise stacktrace changes.
+__attribute__((noinline)) void bad_function() {
+ char buffer[] = "hello\0XXX";
+ // CHECK: strncat-param-overlap: memory ranges
+ // CHECK: [{{0x.*,[ ]*0x.*}}) and [{{0x.*,[ ]*0x.*}}) overlap
+ // CHECK: {{#0 0x.* in .*strncat}}
+ // CHECK: {{#1 0x.* in bad_function.*strncat-overlap.cpp:}}[[@LINE+2]]
+ // CHECK: {{#2 0x.* in main .*strncat-overlap.cpp:}}[[@LINE+5]]
+ strncat(buffer, buffer + 1, 3); // BOOM
+}
+
+int main(int argc, char **argv) {
+ bad_function();
+ return 0;
+}
\ No newline at end of file
diff --git a/compiler-rt/test/asan/TestCases/strncpy-overlap.cpp b/compiler-rt/test/asan/TestCases/strncpy-overlap.cpp
new file mode 100644
index 000000000000..679dd67e65e2
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/strncpy-overlap.cpp
@@ -0,0 +1,48 @@
+// RUN: %clangxx_asan -O0 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O1 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O2 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+//
+// RUN: %clangxx_asan -O3 -fno-builtin %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: echo "interceptor_via_fun:bad_function" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+// RUN: echo "interceptor_name:strncpy" > %t.supp
+// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t
+
+// UNSUPPORTED: android
+
+#include <string.h>
+
+
+// Don't inline function otherwise stacktrace changes.
+__attribute__((noinline)) void bad_function() {
+ char buffer[] = "hello";
+ // CHECK: strncpy-param-overlap: memory ranges
+ // CHECK: [{{0x.*,[ ]*0x.*}}) and [{{0x.*,[ ]*0x.*}}) overlap
+ // CHECK: {{#0 0x.* in .*strncpy}}
+ // CHECK: {{#1 0x.* in bad_function.*strncpy-overlap.cpp:}}[[@LINE+2]]
+ // CHECK: {{#2 0x.* in main .*strncpy-overlap.cpp:}}[[@LINE+5]]
+ strncpy(buffer, buffer + 1, 5); // BOOM
+}
+
+int main(int argc, char **argv) {
+ bad_function();
+ return 0;
+}
\ No newline at end of file
More information about the llvm-commits
mailing list