From: Shraiysh Vaishay Date: Wed, 25 May 2022 11:49:09 +0000 (+0530) Subject: [mlir][openmp] Add check for types of operands in omp.atomic.write X-Git-Tag: upstream/15.0.7~6769 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=512d06b04513dc8c859567e215a13ba8d312095d;p=platform%2Fupstream%2Fllvm.git [mlir][openmp] Add check for types of operands in omp.atomic.write 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 --- diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index 3c86243..23a25fc 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -838,6 +838,9 @@ LogicalResult AtomicWriteOp::verify() { "memory-order must not be acq_rel or acquire for atomic writes"); } } + if (address().getType().cast().getElementType() != + value().getType()) + return emitError("address must dereference to value type"); return verifySynchronizationHint(*this, hint_val()); } diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir b/mlir/test/Dialect/OpenMP/invalid.mlir index 3459ee7..ed5bc00 100644 --- a/mlir/test/Dialect/OpenMP/invalid.mlir +++ b/mlir/test/Dialect/OpenMP/invalid.mlir @@ -600,6 +600,14 @@ func.func @omp_atomic_write6(%addr : memref, %val : i32) { // ----- +func.func @omp_atomic_write(%addr : memref>, %val : i32) { + // expected-error @below {{address must dereference to value type}} + omp.atomic.write %addr = %val : memref>, i32 + return +} + +// ----- + func.func @omp_atomic_update1(%x: memref, %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 {