1 | /* |
2 | * parallel-simple.c -- Archer testcase |
3 | */ |
4 | |
5 | //===----------------------------------------------------------------------===// |
6 | // |
7 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
8 | // |
9 | // See tools/archer/LICENSE.txt for details. |
10 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | |
15 | // RUN: %libarcher-compile && env OMP_TOOL_VERBOSE_INIT=stderr %libarcher-run 2>&1 | FileCheck %s --check-prefixes CHECK,TSAN_ON |
16 | // RUN: %clang-archer %openmp_flags %flags %s -o %t && env OMP_TOOL_VERBOSE_INIT=stderr %t 2>&1 | FileCheck %s --check-prefixes CHECK,TSAN_OFF |
17 | // REQUIRES: tsan |
18 | #include <omp.h> |
19 | #include <stdio.h> |
20 | |
21 | // TSAN_ON: ----- START LOGGING OF TOOL REGISTRATION ----- |
22 | // TSAN_ON-NEXT: Search for OMP tool in current address space... Failed. |
23 | // TSAN_ON-NEXT: No OMP_TOOL_LIBRARIES defined. |
24 | // TSAN_ON-NEXT: ...searching tool libraries failed. Using archer tool. |
25 | // TSAN_ON-NEXT: Opening libarcher.so... Success. |
26 | // TSAN_ON-NEXT: Searching for ompt_start_tool in libarcher.so... Success. |
27 | // TSAN_ON-NEXT: Tool was started and is using the OMPT interface. |
28 | // TSAN_ON-NEXT: ----- END LOGGING OF TOOL REGISTRATION ----- |
29 | |
30 | // TSAN_OFF: ----- START LOGGING OF TOOL REGISTRATION ----- |
31 | // TSAN_OFF-NEXT: Search for OMP tool in current address space... Failed. |
32 | // TSAN_OFF-NEXT: No OMP_TOOL_LIBRARIES defined. |
33 | // TSAN_OFF-NEXT: ...searching tool libraries failed. Using archer tool. |
34 | // TSAN_OFF-NEXT: Opening libarcher.so... Success. |
35 | // TSAN_OFF-NEXT: Searching for ompt_start_tool in libarcher.so... Found but not using the OMPT interface. |
36 | // TSAN_OFF-NEXT: No OMP tool loaded. |
37 | // TSAN_OFF-NEXT: ----- END LOGGING OF TOOL REGISTRATION ----- |
38 | |
39 | |
40 | int main(int argc, char *argv[]) { |
41 | int var = 0; |
42 | |
43 | #pragma omp parallel num_threads(2) shared(var) |
44 | { |
45 | if (omp_get_thread_num() == 1) { |
46 | var++; |
47 | } |
48 | } // implicit barrier |
49 | |
50 | var++; |
51 | |
52 | fprintf(stderr, format: "DONE\n" ); |
53 | int error = (var != 2); |
54 | return error; |
55 | } |
56 | |
57 | // CHECK-NOT: ThreadSanitizer: data race |
58 | // CHECK-NOT: ThreadSanitizer: reported |
59 | // CHECK-NOT: Warning: please export TSAN_OPTIONS |
60 | // CHECK: DONE |
61 | |