| 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 |
| 10 |
// |
| 11 |
//===----------------------------------------------------------------------===// |
| 12 |
|
| 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> |
| 19 |
|
| 20 |
#define NUM_THREADS 8 |
| 21 |
|
| 22 |
int main(int argc, char *argv[]) { |
| 23 |
int var = 0; |
| 24 |
int i; |
| 25 |
|
| 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++; } |
| 31 |
} |
| 32 |
|
| 33 |
int error = (var != 2); |
| 34 |
fprintf(stderr, "DONE\n"); |
| 35 |
return error; |
| 36 |
} |
| 37 |
|
| 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 |