summaryrefslogtreecommitdiff
path: root/test/tsan/signal_malloc.cc
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-02-14 14:35:48 +0000
committerAlexey Samsonov <samsonov@google.com>2014-02-14 14:35:48 +0000
commite951fe4eec98de20b9b843f97fec2cca84c48b9c (patch)
treee5d5d3dbf11683bfde3cfd829ccea8ddbbc0dd0e /test/tsan/signal_malloc.cc
parentba2d0d7b386f38c97eee11749f2fc75449c2b253 (diff)
Move TSan lit-tests under test/tsan
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201414 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/signal_malloc.cc')
-rw-r--r--test/tsan/signal_malloc.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/tsan/signal_malloc.cc b/test/tsan/signal_malloc.cc
new file mode 100644
index 000000000..ef180b8a2
--- /dev/null
+++ b/test/tsan/signal_malloc.cc
@@ -0,0 +1,26 @@
+// RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static void handler(int, siginfo_t*, void*) {
+ // CHECK: WARNING: ThreadSanitizer: signal-unsafe call inside of a signal
+ // CHECK: #0 malloc
+ // CHECK: #{{(1|2)}} handler(int, siginfo{{(_t)?}}*, void*) {{.*}}signal_malloc.cc:[[@LINE+2]]
+ // CHECK: SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal{{.*}}handler
+ volatile char *p = (char*)malloc(1);
+ p[0] = 0;
+ free((void*)p);
+}
+
+int main() {
+ struct sigaction act = {};
+ act.sa_sigaction = &handler;
+ sigaction(SIGPROF, &act, 0);
+ kill(getpid(), SIGPROF);
+ sleep(1);
+ return 0;
+}
+