Skip to content

Commit 86d68fd

Browse files
committed
[CIR][IR] Bypass get_member verifier for incomplete types
Temporary workaround until we patch the codegen for record types.
1 parent 5364b31 commit 86d68fd

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,12 +2461,17 @@ LogicalResult GetMemberOp::verify() {
24612461
if (!recordTy)
24622462
return emitError() << "expected pointer to a record type";
24632463

2464+
// FIXME: currently we bypass typechecking of incomplete types due to errors
2465+
// in the codegen process. This should be removed once the codegen is fixed.
2466+
if (!recordTy.getBody())
2467+
return mlir::success();
2468+
24642469
if (recordTy.getMembers().size() <= getIndex())
24652470
return emitError() << "member index out of bounds";
24662471

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

clang/test/CIR/IR/getmember.cir

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: cir-opt %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
!u16i = !cir.int<u, 16>
5+
!u32i = !cir.int<u, 32>
6+
7+
!ty_22Class22 = !cir.struct<class "Class" {!u16i, !u32i}>
8+
!ty_22Incomplete22 = !cir.struct<struct "Incomplete" incomplete>
9+
!ty_22Struct22 = !cir.struct<struct "Struct" {!u16i, !u32i}>
10+
11+
module {
12+
cir.func @shouldGetStructMember(%arg0 : !cir.ptr<!ty_22Struct22>) {
13+
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Struct22> -> !cir.ptr<!u32i>
14+
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Struct22> -> !cir.ptr<!u32i>
15+
cir.return
16+
}
17+
18+
// FIXME: remove bypass once codegen for CIR records is patched.
19+
cir.func @shouldBypassMemberIndexCheckForIncompleteRecords(%arg0 : !cir.ptr<!ty_22Incomplete22>) {
20+
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Incomplete22> -> !cir.ptr<!u32i>
21+
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Incomplete22> -> !cir.ptr<!u32i>
22+
cir.return
23+
}
24+
25+
// FIXME: remove bypass once codegen for CIR class records is patched.
26+
cir.func @shouldBypassMemberTypeCheckForClassRecords(%arg0 : !cir.ptr<!ty_22Class22>) {
27+
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Class22> -> !cir.ptr<!cir.ptr<!u32i>>
28+
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Class22> -> !cir.ptr<!cir.ptr<!u32i>>
29+
cir.return
30+
}
31+
}

clang/test/CIR/IR/invalid.cir

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,29 @@ module {
522522
cir.throw(%11 : !cir.ptr<!cir.ptr<!u8i>>) // expected-error {{'type_info' symbol attribute missing}}
523523
}
524524
}
525+
526+
// -----
527+
528+
!u16i = !cir.int<u, 16>
529+
!u32i = !cir.int<u, 32>
530+
!struct = !cir.struct<struct "Struct" {!u16i, !u32i}>
531+
module {
532+
cir.func @memeber_index_out_of_bounds(%arg0 : !cir.ptr<!struct>) {
533+
// expected-error@+1 {{member index out of bounds}}
534+
%0 = cir.get_member %arg0[2] {name = "test"} : !cir.ptr<!struct> -> !cir.ptr<!u32i>
535+
cir.return
536+
}
537+
}
538+
539+
// -----
540+
541+
!u16i = !cir.int<u, 16>
542+
!u32i = !cir.int<u, 32>
543+
!struct = !cir.struct<struct "Struct" {!u16i, !u32i}>
544+
module {
545+
cir.func @memeber_type_mismatch(%arg0 : !cir.ptr<!struct>) {
546+
// expected-error@+1 {{member type mismatch}}
547+
%0 = cir.get_member %arg0[0] {name = "test"} : !cir.ptr<!struct> -> !cir.ptr<!u32i>
548+
cir.return
549+
}
550+
}

0 commit comments

Comments
 (0)