diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 1feb631bfcdf..e4c136263b84 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -5481,7 +5481,7 @@ def AtomicXchg : CIR_Op<"atomic.xchg", [AllTypesMatch<["result", "val"]>]> { `:` type($result) attr-dict }]; - let hasVerifier = 0; + let hasVerifier = 1; } def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg", @@ -5524,7 +5524,7 @@ def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg", `:` `(` type($old) `,` type($cmp) `)` attr-dict }]; - let hasVerifier = 0; + let hasVerifier = 1; } def MemScope_SingleThread : I32EnumAttrCase<"MemScope_SingleThread", diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 18e4adf19d53..6b4e8943e07d 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -468,6 +468,29 @@ LogicalResult cir::ContinueOp::verify() { return success(); } +//===----------------------------------------------------------------------===// +// AtomicXchg +//===----------------------------------------------------------------------===// +LogicalResult cir::AtomicXchg::verify() { + if (getPtr().getType().getPointee() != getVal().getType()) + return emitOpError("ptr type and val type must match"); + + return success(); +} + +//===----------------------------------------------------------------------===// +// AtomicCmpXchg +//===----------------------------------------------------------------------===// +LogicalResult cir::AtomicCmpXchg::verify() { + auto pointeeType = getPtr().getType().getPointee(); + + if (pointeeType != getExpected().getType() or + pointeeType != getDesired().getType()) + return emitOpError("ptr, expected and desired types must match"); + + return success(); +} + //===----------------------------------------------------------------------===// // CastOp //===----------------------------------------------------------------------===// diff --git a/clang/test/CIR/IR/invalid.cir b/clang/test/CIR/IR/invalid.cir index c628e3c2b46b..285a6415e40c 100644 --- a/clang/test/CIR/IR/invalid.cir +++ b/clang/test/CIR/IR/invalid.cir @@ -1081,6 +1081,26 @@ cir.func @bad_fetch(%x: !cir.ptr, %y: !cir.float) -> () { // ----- +!u32i = !cir.int +!u64i = !cir.int +cir.func @bad_xchg(%x: !cir.ptr, %y: !u64i) -> () { + // expected-error@+1 {{ptr type and val type must match}} + %13 = cir.atomic.xchg(%x: !cir.ptr, %y: !u64i, seq_cst) : !u64i + cir.return +} + +// ----- + +!u32i = !cir.int +!u64i = !cir.int +cir.func @bad_cmp_xchg(%x: !cir.ptr, %y: !u64i, %z: !u64i) -> () { + // expected-error@+1 {{ptr, expected and desired types must match}} + %14, %15 = cir.atomic.cmp_xchg(%x : !cir.ptr, %y : !u64i, %z : !u64i, success = seq_cst, failure = seq_cst) align(8) weak : (!u64i, !cir.bool) + cir.return +} + +// ----- + cir.func @bad_operands_for_nowrap(%x: !cir.float, %y: !cir.float) { // expected-error@+1 {{only operations on integer values may have nsw/nuw flags}} %0 = cir.binop(add, %x, %y) nsw : !cir.float