Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down
20 changes: 20 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,26 @@ cir.func @bad_fetch(%x: !cir.ptr<!cir.float>, %y: !cir.float) -> () {

// -----

!u32i = !cir.int<u, 32>
!u64i = !cir.int<u, 64>
cir.func @bad_xchg(%x: !cir.ptr<!u32i>, %y: !u64i) -> () {
// expected-error@+1 {{ptr type and val type must match}}
%13 = cir.atomic.xchg(%x: !cir.ptr<!u32i>, %y: !u64i, seq_cst) : !u64i
cir.return
}

// -----

!u32i = !cir.int<u, 32>
!u64i = !cir.int<u, 64>
cir.func @bad_cmp_xchg(%x: !cir.ptr<!u32i>, %y: !u64i, %z: !u64i) -> () {
// expected-error@+1 {{ptr, expected and desired types must match}}
%14, %15 = cir.atomic.cmp_xchg(%x : !cir.ptr<!u32i>, %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
Expand Down
Loading