[Openmp-commits] [compiler-rt] [openmp] [clang] [TSan][OpenMP][Archer] Treat all reduction operations as atomic (PR #74631)

via Openmp-commits openmp-commits at lists.llvm.org
Wed Dec 6 09:44:34 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 56248caa3b427b0c0700f910d0b7b3e1b175bff1 669ddace7494027779b2501805353577efa1ea18 -- openmp/tools/archer/tests/races/parallel-for-array-reduction-no-barrier.c openmp/tools/archer/tests/races/parallel-for-array-reduction-nowait.c openmp/tools/archer/tests/races/parallel-for-reduction-no-barrier.c openmp/tools/archer/tests/races/parallel-for-reduction-nowait.c openmp/tools/archer/tests/reduction/parallel-for-array-reduction-barrier.c openmp/tools/archer/tests/reduction/parallel-for-reduction-barrier.c clang/lib/CodeGen/CGOpenMPRuntime.cpp compiler-rt/lib/tsan/rtl/tsan_interface_ann.cpp compiler-rt/lib/tsan/rtl/tsan_rtl.cpp compiler-rt/lib/tsan/rtl/tsan_rtl.h compiler-rt/lib/tsan/rtl/tsan_shadow.h openmp/tools/archer/ompt-tsan.cpp openmp/tools/archer/tests/reduction/parallel-reduction-nowait.c openmp/tools/archer/tests/reduction/parallel-reduction.c
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
index c829247088..cdbe4cb344 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
@@ -1055,12 +1055,12 @@ void ThreadIgnoreEnd(ThreadState *thr) {
 
 void ThreadAtomicBegin(ThreadState* thr, uptr pc) {
   thr->all_atomic++;
-//  CHECK_GT(thr->ignore_reads_and_writes, 0);
+  //  CHECK_GT(thr->ignore_reads_and_writes, 0);
   CHECK_EQ(thr->all_atomic, 1);
   thr->fast_state.SetAtomicBit();
 }
 
-void ThreadAtomicEnd(ThreadState *thr) {
+void ThreadAtomicEnd(ThreadState* thr) {
   CHECK_GT(thr->all_atomic, 0);
   thr->all_atomic--;
   if (thr->all_atomic == 0) {
diff --git a/openmp/tools/archer/ompt-tsan.cpp b/openmp/tools/archer/ompt-tsan.cpp
index ece791683e..673b23aca8 100644
--- a/openmp/tools/archer/ompt-tsan.cpp
+++ b/openmp/tools/archer/ompt-tsan.cpp
@@ -149,7 +149,7 @@ static ArcherFlags *archer_flags;
 // Thread Sanitizer is a tool that finds races in code.
 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
 // tsan detects these exact functions by name.
-//extern "C" {
+// extern "C" {
 static void (*AnnotateHappensAfter)(const char *, int, const volatile void *);
 static void (*AnnotateHappensBefore)(const char *, int, const volatile void *);
 static void (*AnnotateIgnoreWritesBegin)(const char *, int);
@@ -177,7 +177,7 @@ static void (*AnnotateReductionEnd)(const char *, int);
 // Resume checking for racy writes.
 #define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
 
-// Maps to either AnnotateAllAtomics or AnnotateIgnoreWrites 
+// Maps to either AnnotateAllAtomics or AnnotateIgnoreWrites
 #define TsanReductionBegin() AnnotateReductionBegin(__FILE__, __LINE__)
 #define TsanReductionEnd() AnnotateReductionEnd(__FILE__, __LINE__)
 
@@ -1187,13 +1187,17 @@ static int ompt_tsan_initialize(ompt_function_lookup_t lookup, int device_num,
       (void (*)(const char *, int, const volatile void *, size_t)));
   findTsanFunction(__tsan_func_entry, (void (*)(const void *)));
   findTsanFunction(__tsan_func_exit, (void (*)(void)));
-  findTsanFunctionName(AnnotateReductionBegin, AnnotateAllAtomicBegin, (void (*)(const char *, int)));
-  findTsanFunctionName(AnnotateReductionEnd, AnnotateAllAtomicEnd, (void (*)(const char *, int)));
+  findTsanFunctionName(AnnotateReductionBegin, AnnotateAllAtomicBegin,
+                       (void (*)(const char *, int)));
+  findTsanFunctionName(AnnotateReductionEnd, AnnotateAllAtomicEnd,
+                       (void (*)(const char *, int)));
   if (!AnnotateReductionBegin) {
     AnnotateReductionBegin = AnnotateIgnoreWritesBegin;
     AnnotateReductionEnd = AnnotateIgnoreWritesEnd;
     if (archer_flags->verbose)
-      std::cout << "Archer uses fallback solution for reductions: might miss some race" << std::endl;
+      std::cout << "Archer uses fallback solution for reductions: might miss "
+                   "some race"
+                << std::endl;
   }
 
   SET_CALLBACK(thread_begin);
diff --git a/openmp/tools/archer/tests/races/parallel-for-array-reduction-no-barrier.c b/openmp/tools/archer/tests/races/parallel-for-array-reduction-no-barrier.c
index 2cdfb811fc..511a21013d 100644
--- a/openmp/tools/archer/tests/races/parallel-for-array-reduction-no-barrier.c
+++ b/openmp/tools/archer/tests/races/parallel-for-array-reduction-no-barrier.c
@@ -22,15 +22,16 @@
 #include <stdio.h>
 
 int main(int argc, char *argv[]) {
-  int var[10]={0,1,2,3,4,5,6,7,8,9};
-  
+  int var[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
 #pragma omp parallel
   {
 #pragma omp masked
     var[5] = 23;
 #pragma omp for reduction(+ : var)
-    for (int i = 0; i < 1000; i++)
-      { var[i%10]++; }
+    for (int i = 0; i < 1000; i++) {
+      var[i % 10]++;
+    }
   }
   fprintf(stderr, "DONE\n");
   int error = (var[5] != 123);
diff --git a/openmp/tools/archer/tests/races/parallel-for-array-reduction-nowait.c b/openmp/tools/archer/tests/races/parallel-for-array-reduction-nowait.c
index 6ca17fcca6..bdac83d7ca 100644
--- a/openmp/tools/archer/tests/races/parallel-for-array-reduction-nowait.c
+++ b/openmp/tools/archer/tests/races/parallel-for-array-reduction-nowait.c
@@ -22,13 +22,14 @@
 #include <stdio.h>
 
 int main(int argc, char *argv[]) {
-  int var[10]={0,1,2,3,4,5,6,7,8,9};
-  
+  int var[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
 #pragma omp parallel
   {
 #pragma omp for reduction(+ : var) nowait
-    for (int i = 0; i < 1000; i++)
-      { var[i%10]++; }
+    for (int i = 0; i < 1000; i++) {
+      var[i % 10]++;
+    }
 #pragma omp masked
     var[5] += 23;
   }
diff --git a/openmp/tools/archer/tests/races/parallel-for-reduction-no-barrier.c b/openmp/tools/archer/tests/races/parallel-for-reduction-no-barrier.c
index 3cc63cfab1..3ea874a0de 100644
--- a/openmp/tools/archer/tests/races/parallel-for-reduction-no-barrier.c
+++ b/openmp/tools/archer/tests/races/parallel-for-reduction-no-barrier.c
@@ -23,14 +23,15 @@
 
 int main(int argc, char *argv[]) {
   int var = 0;
-  
+
 #pragma omp parallel
   {
 #pragma omp masked
     var = 23;
 #pragma omp for reduction(+ : var)
-    for (int i = 0; i < 100; i++)
-      { var++; }
+    for (int i = 0; i < 100; i++) {
+      var++;
+    }
   }
   fprintf(stderr, "DONE\n");
   int error = (var != 123);
diff --git a/openmp/tools/archer/tests/races/parallel-for-reduction-nowait.c b/openmp/tools/archer/tests/races/parallel-for-reduction-nowait.c
index 4c24e8a4f8..11afceb671 100644
--- a/openmp/tools/archer/tests/races/parallel-for-reduction-nowait.c
+++ b/openmp/tools/archer/tests/races/parallel-for-reduction-nowait.c
@@ -23,12 +23,13 @@
 
 int main(int argc, char *argv[]) {
   int var = 0;
-  
+
 #pragma omp parallel
   {
 #pragma omp for reduction(+ : var) nowait
-    for (int i = 0; i < 100; i++)
-      { var++; }
+    for (int i = 0; i < 100; i++) {
+      var++;
+    }
 #pragma omp masked
     var = 23;
   }
diff --git a/openmp/tools/archer/tests/reduction/parallel-for-array-reduction-barrier.c b/openmp/tools/archer/tests/reduction/parallel-for-array-reduction-barrier.c
index 2ac9ec449b..d5d7ca5250 100644
--- a/openmp/tools/archer/tests/reduction/parallel-for-array-reduction-barrier.c
+++ b/openmp/tools/archer/tests/reduction/parallel-for-array-reduction-barrier.c
@@ -22,21 +22,22 @@
 #include <stdio.h>
 
 int main(int argc, char *argv[]) {
-  int var[10]={0,1,2,3,4,5,6,7,8,9};
-  
+  int var[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
 #pragma omp parallel
   {
 #pragma omp masked
     var[5] = 23;
 #pragma omp barrier
 #pragma omp for reduction(+ : var)
-    for (int i = 0; i < 1000; i++)
-      { var[i%10]++; }
+    for (int i = 0; i < 1000; i++) {
+      var[i % 10]++;
+    }
 #pragma omp masked
     var[4] += 42;
   }
   fprintf(stderr, "DONE\n");
-  int error = (var[5] != 23+100) || (var[4] != 4+100+42);
+  int error = (var[5] != 23 + 100) || (var[4] != 4 + 100 + 42);
   return error;
 }
 
diff --git a/openmp/tools/archer/tests/reduction/parallel-for-reduction-barrier.c b/openmp/tools/archer/tests/reduction/parallel-for-reduction-barrier.c
index 5050684ce2..5ee6928161 100644
--- a/openmp/tools/archer/tests/reduction/parallel-for-reduction-barrier.c
+++ b/openmp/tools/archer/tests/reduction/parallel-for-reduction-barrier.c
@@ -23,20 +23,21 @@
 
 int main(int argc, char *argv[]) {
   int var = 0;
-  
+
 #pragma omp parallel
   {
 #pragma omp masked
     var = 23;
 #pragma omp barrier
 #pragma omp for reduction(+ : var)
-    for (int i = 0; i < 100; i++)
-      { var++; }
+    for (int i = 0; i < 100; i++) {
+      var++;
+    }
 #pragma omp masked
     var += 42;
   }
   fprintf(stderr, "DONE\n");
-  int error = (var != 23+100+42);
+  int error = (var != 23 + 100 + 42);
   return error;
 }
 
diff --git a/openmp/tools/archer/tests/reduction/parallel-reduction.c b/openmp/tools/archer/tests/reduction/parallel-reduction.c
index afb2863235..887fe2e018 100644
--- a/openmp/tools/archer/tests/reduction/parallel-reduction.c
+++ b/openmp/tools/archer/tests/reduction/parallel-reduction.c
@@ -23,7 +23,7 @@
 
 int main(int argc, char *argv[]) {
   int var = 0;
-  
+
 #pragma omp parallel reduction(+ : var)
   { var = 1; }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/74631


More information about the Openmp-commits mailing list