File: main_tid.mm

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,696 kB
  • sloc: cpp: 7,438,781; ansic: 1,393,871; asm: 1,012,926; python: 241,771; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 8,596; ml: 5,082; perl: 4,730; makefile: 3,591; awk: 3,523; javascript: 2,251; xml: 892; fortran: 672
file content (52 lines) | stat: -rw-r--r-- 1,415 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// RUN: %clang_tsan %s -o %t -framework Foundation
// RUN: %deflake %run %t 2>&1 | FileCheck %s

#import <pthread.h>
#import <stdio.h>
#import <stdlib.h>

extern "C" {
void __tsan_on_report(void *report);
int __tsan_get_report_thread(void *report, unsigned long idx, int *tid,
                             uint64_t *os_id, int *running,
                             const char **name, int *parent_tid, void **trace,
                             unsigned long trace_size);
}

// Required for dyld macOS 12.0+
#if (__APPLE__)
__attribute__((weak))
#endif
__attribute__((disable_sanitizer_instrumentation))
extern "C" void
__tsan_on_report(void *report) {
  fprintf(stderr, "__tsan_on_report(%p)\n", report);

  int tid;
  uint64_t os_id;
  int running;
  const char *name;
  int parent_tid;
  void *trace[16] = {0};
  __tsan_get_report_thread(report, 0, &tid, &os_id, &running, &name, &parent_tid, trace, 16);
  fprintf(stderr, "tid = %d, os_id = %lu\n", tid, os_id);
}

int main() {
  fprintf(stderr, "Hello world.\n");

  uint64_t threadid;
  pthread_threadid_np(NULL, &threadid);
  fprintf(stderr, "pthread_threadid_np = %llu\n", threadid);

  pthread_mutex_t m;
  pthread_mutex_init(&m, NULL);
  pthread_mutex_unlock(&m);
  fprintf(stderr, "Done.\n");
}

// CHECK: Hello world.
// CHECK: pthread_threadid_np = [[ADDR:[0-9]+]]
// CHECK: WARNING: ThreadSanitizer
// CHECK: tid = 0, os_id = [[ADDR]]
// CHECK: Done.