8000 [CIR][IR] Bypass get_member verifier for incomplete types by sitio-couto · Pull Request #257 · llvm/clangir · GitHub
[go: up one dir, main page]

Skip to content

[CIR][IR] Bypass get_member verifier for incomplete types #257

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 1 commit into from
Sep 13, 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
11 changes: 8 additions & 3 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2461,12 +2461,17 @@ LogicalResult GetMemberOp::verify() {
if (!recordTy)
return emitError() << "expected pointer to a record type";

// FIXME: currently we bypass typechecking of incomplete types due to errors
// in the codegen process. This should be removed once the codegen is fixed.
if (!recordTy.getBody())
return mlir::success();

if (recordTy.getMembers().size() <= getIndex())
return emitError() << "member index out of bounds";

// FIXME(cir): Member type check is disabled for classes and incomplete types
// as the codegen for these still need to be patched.
if (!recordTy.isClass() && !recordTy.getBody() &&
// FIXME(cir): member type check is disabled for classes as the codegen for
// these still need to be patched.
if (!recordTy.isClass() &&
recordTy.getMembers()[getIndex()] != getResultTy().getPointee())
return emitError() << "member type mismatch";

Expand Down
31 changes: 31 additions & 0 deletions clang/test/CIR/IR/getmember.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// RUN: cir-opt %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

!u16i = !cir.int<u, 16>
!u32i = !cir.int<u, 32>

!ty_22Class22 = !cir.struct<class "Class" {!u16i, !u32i}>
!ty_22Incomplete22 = !cir.struct<struct "Incomplete" incomplete>
!ty_22Struct22 = !cir.struct<struct "Struct" {!u16i, !u32i}>

module {
cir.func @shouldGetStructMember(%arg0 : !cir.ptr<!ty_22Struct22>) {
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Struct22> -> !cir.ptr<!u32i>
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Struct22> -> !cir.ptr<!u32i>
cir.return
}

// FIXME: remove bypass once codegen for CIR records is patched.
cir.func @shouldBypassMemberIndexCheckForIncompleteRecords(%arg0 : !cir.ptr<!ty_22Incomplete22>) {
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Incomplete22> -> !cir.ptr<!u32i>
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Incomplete22> -> !cir.ptr<!u32i>
cir.return
}

// FIXME: remove bypass once codegen for CIR class records is patched.
cir.func @shouldBypassMemberTypeCheckForClassRecords(%arg0 : !cir.ptr<!ty_22Class22>) {
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Class22> -> !cir.ptr<!cir.ptr<!u32i>>
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Class22> -> !cir.ptr<!cir.ptr<!u32i>>
cir.return
}
}
26 changes: 26 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,29 @@ module {
cir.throw(%11 : !cir.ptr<!cir.ptr<!u8i>>) // expected-error {{'type_info' symbol attribute missing}}
}
}

// -----

!u16i = !cir.int<u, 16>
!u32i = !cir.int<u, 32>
!struct = !cir.struct<struct "Struct" {!u16i, !u32i}>
module {
cir.func @memeber_index_out_of_bounds(%arg0 : !cir.ptr<!struct>) {
// expected-error@+1 {{member index out of bounds}}
%0 = cir.get_member %arg0[2] {name = "test"} : !cir.ptr<!struct> -> !cir.ptr<!u32i>
cir.return
}
}

// -----

!u16i = !cir.int<u, 16>
!u32i = !cir.int<u, 32>
!struct = !cir.struct<struct "Struct" {!u16i, !u32i}>
module {
cir.func @memeber_type_mismatch(%arg0 : !cir.ptr<!struct>) {
// expected-error@+1 {{member type mismatch}}
%0 = cir.get_member %arg0[0] {name = "test"} : !cir.ptr<!struct> -> !cir.ptr<!u32i>
cir.return
}
}
0