[mlir][openmp] Add check for types of operands in omp.atomic.write
authorShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Wed, 25 May 2022 11:49:09 +0000 (17:19 +0530)
committerShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Wed, 25 May 2022 11:52:16 +0000 (17:22 +0530)
This patch makes sure that the address dereferences to value in
omp.atomic.write operation.

Reviewed By: kiranchandramohan, peixin

Differential Revision: https://reviews.llvm.org/D126272

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
mlir/test/Dialect/OpenMP/invalid.mlir

index 3c86243..23a25fc 100644 (file)
@@ -838,6 +838,9 @@ LogicalResult AtomicWriteOp::verify() {
           "memory-order must not be acq_rel or acquire for atomic writes");
     }
   }
+  if (address().getType().cast<PointerLikeType>().getElementType() !=
+      value().getType())
+    return emitError("address must dereference to value type");
   return verifySynchronizationHint(*this, hint_val());
 }
 
index 3459ee7..ed5bc00 100644 (file)
@@ -600,6 +600,14 @@ func.func @omp_atomic_write6(%addr : memref<i32>, %val : i32) {
 
 // -----
 
+func.func @omp_atomic_write(%addr : memref<memref<i32>>, %val : i32) {
+  // expected-error @below {{address must dereference to value type}}
+  omp.atomic.write %addr = %val : memref<memref<i32>>, i32
+  return
+}
+
+// -----
+
 func.func @omp_atomic_update1(%x: memref<i32>, %expr: f32) {
   // expected-error @below {{the type of the operand must be a pointer type whose element type is the same as that of the region argument}}
   omp.atomic.update %x : memref<i32> {