xref: /llvm-project/openmp/tools/archer/tests/races/parallel-simple.c (revision dedcda45c4fc3bdf8b702e5ee7b943f4c0908ae6)
12b8115b1Sprotze@itc.rwth-aachen.de /*
22b8115b1Sprotze@itc.rwth-aachen.de  * parallel-simple.c -- Archer testcase
32b8115b1Sprotze@itc.rwth-aachen.de  */
42b8115b1Sprotze@itc.rwth-aachen.de //===----------------------------------------------------------------------===//
52b8115b1Sprotze@itc.rwth-aachen.de //
62b8115b1Sprotze@itc.rwth-aachen.de // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
72b8115b1Sprotze@itc.rwth-aachen.de //
82b8115b1Sprotze@itc.rwth-aachen.de // See tools/archer/LICENSE.txt for details.
92b8115b1Sprotze@itc.rwth-aachen.de // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
102b8115b1Sprotze@itc.rwth-aachen.de //
112b8115b1Sprotze@itc.rwth-aachen.de //===----------------------------------------------------------------------===//
122b8115b1Sprotze@itc.rwth-aachen.de 
132b8115b1Sprotze@itc.rwth-aachen.de // RUN: %libarcher-compile-and-run-race | FileCheck %s
14fdc9dfc8SJoachim Protze // RUN: %libarcher-compile-and-run-race-noserial | FileCheck %s
1577ad98c8Sprotze@itc.rwth-aachen.de // REQUIRES: tsan
162b8115b1Sprotze@itc.rwth-aachen.de #include <omp.h>
172b8115b1Sprotze@itc.rwth-aachen.de #include <stdio.h>
182b8115b1Sprotze@itc.rwth-aachen.de 
main(int argc,char * argv[])192b8115b1Sprotze@itc.rwth-aachen.de int main(int argc, char *argv[]) {
202b8115b1Sprotze@itc.rwth-aachen.de   int var = 0;
212b8115b1Sprotze@itc.rwth-aachen.de 
224acc2f29SJoachim Protze #pragma omp parallel num_threads(8) shared(var)
232b8115b1Sprotze@itc.rwth-aachen.de   { var++; }
242b8115b1Sprotze@itc.rwth-aachen.de 
252b8115b1Sprotze@itc.rwth-aachen.de   int error = (var != 2);
262b8115b1Sprotze@itc.rwth-aachen.de   fprintf(stderr, "DONE\n");
272b8115b1Sprotze@itc.rwth-aachen.de   return error;
282b8115b1Sprotze@itc.rwth-aachen.de }
292b8115b1Sprotze@itc.rwth-aachen.de 
302b8115b1Sprotze@itc.rwth-aachen.de // CHECK: WARNING: ThreadSanitizer: data race
312b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT:   {{(Write|Read)}} of size 4
322b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT: #0 {{.*}}parallel-simple.c:23
332b8115b1Sprotze@itc.rwth-aachen.de // CHECK:   Previous write of size 4
342b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT: #0 {{.*}}parallel-simple.c:23
352b8115b1Sprotze@itc.rwth-aachen.de // CHECK: DONE
36*dedcda45SJoachim Jenke // CHECK: ThreadSanitizer: reported {{[1-7]}} warnings
37