llvm-project/compiler-rt/test/tsan/signal_malloc.cpp
Dmitry Vyukov 9ef9d01a50 tsan: extend signal_malloc test
Test that we report the warning for free()
and ensure the test finishes as we usually do with "DONE".

Depends on D106951.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D106952
2021-07-28 17:35:13 +02:00

31 lines
1.1 KiB
C++

// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include "test.h"
#include <signal.h>
#include <sys/types.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.cpp:[[@LINE+2]]
// CHECK: SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal{{.*}}handler
volatile char *p = (char*)malloc(1);
p[0] = 0;
// CHECK: WARNING: ThreadSanitizer: signal-unsafe call inside of a signal
// CHECK: #0 free
// CHECK: #{{(1|2)}} handler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_malloc.cpp:[[@LINE+2]]
// CHECK: SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal{{.*}}handler
free((void*)p);
}
int main() {
struct sigaction act = {};
act.sa_sigaction = &handler;
sigaction(SIGPROF, &act, 0);
kill(getpid(), SIGPROF);
sleep(1); // let the signal handler run
fprintf(stderr, "DONE\n");
// CHECK: DONE
return 0;
}