Skip to content

[CIR][Dialect] Verify bitcast does not contain address space conversion #813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 13 additions & 3 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,21 @@ LogicalResult CastOp::verify() {
if (isa<StructType>(srcType) || isa<StructType>(resType))
return success();

// Handle the pointer types first.
auto srcPtrTy = mlir::dyn_cast<mlir::cir::PointerType>(srcType);
auto resPtrTy = mlir::dyn_cast<mlir::cir::PointerType>(resType);

if (srcPtrTy && resPtrTy) {
if (srcPtrTy.getAddrSpace() != resPtrTy.getAddrSpace()) {
return emitOpError() << "result type address space does not match the "
"address space of the operand";
}
return success();
}

// This is the only cast kind where we don't want vector types to decay
// into the element type.
if ((!mlir::isa<mlir::cir::PointerType>(getSrc().getType()) ||
!mlir::isa<mlir::cir::PointerType>(getResult().getType())) &&
(!mlir::isa<mlir::cir::VectorType>(getSrc().getType()) ||
if ((!mlir::isa<mlir::cir::VectorType>(getSrc().getType()) ||
!mlir::isa<mlir::cir::VectorType>(getResult().getType())))
return emitOpError()
<< "requires !cir.ptr or !cir.vector type for source and result";
Expand Down
15 changes: 15 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1298,3 +1298,18 @@ module {
cir.return
}
}

// -----

!s32i = !cir.int<s, 32>

module {

cir.func @test_bitcast_addrspace() {
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["tmp"] {alignment = 4 : i64}
// expected-error@+1 {{'cir.cast' op result type address space does not match the address space of the operand}}
%1 = cir.cast(bitcast, %0 : !cir.ptr<!s32i>), !cir.ptr<!s32i, addrspace(offload_local)>
}

}