Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / tools / archer / tests / races / task-two.c
blobfad36973184a3c45f21749025fd27c67db4e0244
1 /*
2 * task-two.c -- Archer testcase
3 */
4 //===----------------------------------------------------------------------===//
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 //
8 // See tools/archer/LICENSE.txt for details.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
13 // RUN: %libarcher-compile-and-run-race | FileCheck %s
14 // RUN: %libarcher-compile-and-run-race-noserial | FileCheck %s
15 // REQUIRES: tsan
16 #include <omp.h>
17 #include <stdio.h>
18 #include <unistd.h>
20 #define NUM_THREADS 8
22 int main(int argc, char *argv[]) {
23 int var = 0;
24 int i;
26 #pragma omp parallel for num_threads(NUM_THREADS) shared(var) \
27 schedule(static, 1)
28 for (i = 0; i < NUM_THREADS; i++) {
29 #pragma omp task shared(var) if (0) // the task is inlined an executed locally
30 { var++; }
33 int error = (var != 2);
34 fprintf(stderr, "DONE\n");
35 return error;
38 // CHECK: WARNING: ThreadSanitizer: data race
39 // CHECK-NEXT: {{(Write|Read)}} of size 4
40 // CHECK-NEXT: #0 {{.*}}task-two.c:30
41 // CHECK: Previous write of size 4
42 // CHECK-NEXT: #0 {{.*}}task-two.c:30
43 // CHECK: DONE
44 // CHECK: ThreadSanitizer: reported {{[0-9]+}} warnings