[Mlir-commits] [mlir] [MLIR][OpenMP] Add verifier to prevent illegal omp.critical nesting (PR #217357)

Aidan Dakhama llvmlistbot at llvm.org
Wed Aug 19 09:57:07 PDT 2026


================
@@ -4828,6 +4828,31 @@ LogicalResult CriticalDeclareOp::verify() {
   return verifySynchronizationHint(*this, getHint());
 }
 
+LogicalResult CriticalOp::verify() {
+  SymbolRefAttr currentName = getNameAttr();
+
+  CriticalOp parentCritical = (*this)->getParentOfType<CriticalOp>();
+
+  while (parentCritical) {
----------------
dakaidan wrote:

You are right – it returns non-direct parents! However, the issue is that we could have a critical region nested between two other critical regions that share a name.

I added another test (@nested_named_critical_interleaved) to clarify this scenario. Without the while loop, checking the innermost @my_mutex_A would only see @my_mutex_B as its parent and stop there, completely missing the grandparent @my_mutex_A one level higher.

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


More information about the Mlir-commits mailing list