[llvm-commits] [compiler-rt] r170207 - /compiler-rt/trunk/lib/tsan/lit_tests/signal_errno.cc

Dmitry Vyukov dvyukov at google.com
Fri Dec 14 06:42:40 PST 2012


Author: dvyukov
Date: Fri Dec 14 08:42:40 2012
New Revision: 170207

URL: http://llvm.org/viewvc/llvm-project?rev=170207&view=rev
Log:
tsan: add test for errno spoiling in signal handler

Added:
    compiler-rt/trunk/lib/tsan/lit_tests/signal_errno.cc

Added: compiler-rt/trunk/lib/tsan/lit_tests/signal_errno.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/signal_errno.cc?rev=170207&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/signal_errno.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/signal_errno.cc Fri Dec 14 08:42:40 2012
@@ -0,0 +1,42 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+
+pthread_t mainth;
+volatile int done;
+
+static void handler(int, siginfo_t*, void*) {
+  errno = 1;
+  done = 1;
+}
+
+static void* sendsignal(void*) {
+  pthread_kill(mainth, SIGPROF);
+  return 0;
+}
+
+int main() {
+  mainth = pthread_self();
+  struct sigaction act = {};
+  act.sa_sigaction = &handler;
+  sigaction(SIGPROF, &act, 0);
+  pthread_t th;
+  pthread_create(&th, 0, sendsignal, 0);
+  while (done == 0) {
+    volatile char *p = (char*)malloc(1);
+    p[0] = 0;
+    free((void*)p);
+    pthread_yield();
+  }
+  pthread_join(th, 0);
+  return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: signal handler spoils errno
+// CHECK:     #0 handler(int, siginfo*, void*) {{.*}}signal_errno.cc
+





More information about the llvm-commits mailing list