Skip to content
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

[CIR] Add validation tests for scalar casts #317

Merged
merged 1 commit into from
Nov 15, 2023
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
4 changes: 2 additions & 2 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ LogicalResult CastOp::verify() {
if (!resType.isa<mlir::cir::BoolType>())
return emitOpError() << "requires !cir.bool type for result";
if (!srcType.isa<mlir::cir::IntType>())
return emitOpError() << "requires integral type for result";
return emitOpError() << "requires integral type for source";
return success();
}
case cir::CastKind::ptr_to_bool: {
if (!resType.isa<mlir::cir::BoolType>())
return emitOpError() << "requires !cir.bool type for result";
if (!srcType.isa<mlir::cir::PointerType>())
return emitOpError() << "requires pointer type for result";
return emitOpError() << "requires pointer type for source";
return success();
}
case cir::CastKind::integral: {
Expand Down
143 changes: 142 additions & 1 deletion clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ cir.func @cast0(%arg0: !u32i) {
// -----

cir.func @cast1(%arg1: f32) {
%1 = cir.cast(int_to_bool, %arg1 : f32), !cir.bool // expected-error {{requires integral type for result}}
%1 = cir.cast(int_to_bool, %arg1 : f32), !cir.bool // expected-error {{requires integral type for source}}
cir.return
}

Expand Down Expand Up @@ -173,6 +173,147 @@ cir.func @cast6(%p: !cir.bool) {

// -----

!u32i = !cir.int<u, 32>
cir.func @cast7(%p: !cir.ptr<!u32i>) {
%2 = cir.cast(ptr_to_bool, %p : !cir.ptr<!u32i>), !u32i // expected-error {{requires !cir.bool type for result}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast8(%p: !u32i) {
%2 = cir.cast(ptr_to_bool, %p : !u32i), !cir.bool // expected-error {{requires pointer type for source}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast9(%p : !u32i) {
%2 = cir.cast(integral, %p : !u32i), f32 // expected-error {{requires !IntegerType for result}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you also found a bug here, this should print !cir.int, I wonder if we are still using mlir::IntegerType instead of cir::IntType or if the error message is just not ideal. Let's track this on another issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast10(%p : f32) {
%2 = cir.cast(integral, %p : f32), !u32i // expected-error {{requires !IntegerType for source}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast11(%p : f32) {
%2 = cir.cast(floating, %p : f32), !u32i // expected-error {{requries floating for source and result}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast12(%p : !u32i) {
%2 = cir.cast(floating, %p : !u32i), f32 // expected-error {{requries floating for source and result}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast13(%p : !u32i) {
%2 = cir.cast(float_to_int, %p : !u32i), !u32i // expected-error {{requires floating for source}}
cir.return
}

// -----

cir.func @cast14(%p : f32) {
%2 = cir.cast(float_to_int, %p : f32), f32 // expected-error {{requires !IntegerType for result}}
cir.return
}

// -----

!u64i = !cir.int<u, 64>
cir.func @cast15(%p : !cir.ptr<!u64i>) {
%2 = cir.cast(int_to_ptr, %p : !cir.ptr<!u64i>), !cir.ptr<!u64i> // expected-error {{requires integer for source}}
cir.return
}

// -----

!u64i = !cir.int<u, 64>
cir.func @cast16(%p : !u64i) {
%2 = cir.cast(int_to_ptr, %p : !u64i), !u64i // expected-error {{requires pointer for result}}
cir.return
}

// -----

!u64i = !cir.int<u, 64>
cir.func @cast17(%p : !u64i) {
%2 = cir.cast(ptr_to_int, %p : !u64i), !u64i // expected-error {{requires pointer for source}}
cir.return
}

// -----

!u64i = !cir.int<u, 64>
cir.func @cast18(%p : !cir.ptr<!u64i>) {
%2 = cir.cast(ptr_to_int, %p : !cir.ptr<!u64i>), !cir.ptr<!u64i> // expected-error {{requires integer for result}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast19(%p : !u32i) {
%2 = cir.cast(float_to_bool, %p : !u32i), !cir.bool // expected-error {{requires float for source}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast20(%p : f32) {
%2 = cir.cast(float_to_bool, %p : f32), !u32i // expected-error {{requires !cir.bool for result}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast21(%p : !u32i) {
%2 = cir.cast(bool_to_int, %p : !u32i), !u32i // expected-error {{requires !cir.bool for source}}
cir.return
}

// -----

cir.func @cast22(%p : !cir.bool) {
%2 = cir.cast(bool_to_int, %p : !cir.bool), f32 // expected-error {{requires !cir.int for result}}
cir.return
}

// -----

cir.func @cast23(%p : !cir.bool) {
%2 = cir.cast(int_to_float, %p : !cir.bool), f32 // expected-error {{requires !cir.int for source}}
cir.return
}

// -----

!u32i = !cir.int<u, 32>
cir.func @cast24(%p : !u32i) {
%2 = cir.cast(int_to_float, %p : !u32i), !cir.bool // expected-error {{requires !cir.float for result}}
cir.return
}

// -----

#false = #cir.bool<false> : !cir.bool
#true = #cir.bool<true> : !cir.bool
cir.func @b0() {
Expand Down