[clang] [OpenMP] Fix atomic compare handling with overloaded operators (PR #141142)

Johannes Doerfert via cfe-commits cfe-commits at lists.llvm.org
Wed May 28 11:17:05 PDT 2025


================
@@ -991,3 +991,34 @@ int mixed() {
   // expected-note at +1 {{in instantiation of function template specialization 'mixed<int>' requested here}}
   return mixed<int>();
 }
+
+#ifdef OMP51
+struct U {};
+struct U operator<(U, U);
+struct U operator>(U, U);
+struct U operator==(U, U);
+
+template <typename T> void templated() {
+  T cx, cv, ce, cd;
+#pragma omp atomic compare capture
+  if (cx == ce) {
+    cx = cd;
+  } else {
+    cv = cx;
+  }
+#pragma omp atomic compare capture
+  {
+    cv = cx;
+    if (ce > cx) {
+      cx = ce;
+    }
+  }
+#pragma omp atomic compare capture
+  {
+    cv = cx;
+    if (cx < ce) {
+      cx = ce;
+    }
+  }
+}
+#endif
----------------
jdoerfert wrote:

We need a similar test as a codegen test as well.

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


More information about the cfe-commits mailing list