60 lines · c
1/*2 * taskwait-depend.c -- Archer testcase3 * derived from DRB165-taskdep4-orig-omp50-yes.c in DataRaceBench4 */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-exception11//12//===----------------------------------------------------------------------===//13 14// RUN: %libarcher-compile-and-run-race | FileCheck %s15// RUN: %libarcher-compile-and-run-race-noserial | FileCheck %s16// REQUIRES: tsan17 18#include "ompt/ompt-signal.h"19#include <omp.h>20#include <stdio.h>21 22void foo() {23 24 int x = 0, y = 2, sem = 0;25 26#pragma omp task depend(inout : x) shared(x, sem)27 {28 OMPT_SIGNAL(sem);29 x++; // 1st Child Task30 }31 32#pragma omp task shared(y, sem)33 {34 OMPT_SIGNAL(sem);35 y--; // 2nd child task36 }37 38 OMPT_WAIT(sem, 2);39#pragma omp taskwait depend(in : x) // 1st taskwait40 41 printf("x=%d\n", x);42 printf("y=%d\n", y);43#pragma omp taskwait // 2nd taskwait44}45 46int main() {47#pragma omp parallel num_threads(2)48#pragma omp single49 foo();50 51 return 0;52}53 54// CHECK: WARNING: ThreadSanitizer: data race55// CHECK-NEXT: {{(Write|Read)}} of size 456// CHECK-NEXT: #0 {{.*}}taskwait-depend.c:4257// CHECK: Previous write of size 458// CHECK-NEXT: #0 {{.*}}taskwait-depend.c:3559// CHECK: ThreadSanitizer: reported {{[0-9]+}} warnings60