File: deep_stack1.cc

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,388 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (57 lines) | stat: -rw-r--r-- 1,144 bytes parent folder | download | duplicates (11)
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
53
54
55
56
57
// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s
// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s
#include "test.h"

volatile int X;
volatile int N;
void (*volatile F)();

static void foo() {
  if (--N == 0)
    X = 42;
  else
    F();
}

void *Thread(void *p) {
#ifdef ORDER1
  barrier_wait(&barrier);
#endif
  F();
#ifdef ORDER2
  barrier_wait(&barrier);
#endif
  return 0;
}

static size_t RoundUp(size_t n, size_t to) {
  return ((n + to - 1) / to) * to;
}

int main() {
  barrier_init(&barrier, 2);
  N = 50000;
  F = foo;
  pthread_t t;
  pthread_attr_t a;
  pthread_attr_init(&a);
  size_t stack_size = N * 256 + (1 << 20);
  stack_size = RoundUp(stack_size, 0x10000);  // round the stack size to 64k
  int ret = pthread_attr_setstacksize(&a, stack_size);
  if (ret) abort();
  pthread_create(&t, &a, Thread, 0);
#ifdef ORDER2
  barrier_wait(&barrier);
#endif
  X = 43;
#ifdef ORDER1
  barrier_wait(&barrier);
#endif

  pthread_join(t, 0);
}

// CHECK: WARNING: ThreadSanitizer: data race
// CHECK:    #100 foo
// We must output suffucuently large stack (at least 100 frames)