File tree Expand file tree Collapse file tree 3 files changed +65
-3
lines changed Expand file tree Collapse file tree 3 files changed +65
-3
lines changed Original file line number Diff line number Diff line change @@ -2475,12 +2475,17 @@ LogicalResult GetMemberOp::verify() {
24752475 if (!recordTy)
24762476 return emitError () << " expected pointer to a record type" ;
24772477
2478+ // FIXME: currently we bypass typechecking of incomplete types due to errors
2479+ // in the codegen process. This should be removed once the codegen is fixed.
2480+ if (!recordTy.getBody ())
2481+ return mlir::success ();
2482+
24782483 if (recordTy.getMembers ().size () <= getIndex ())
24792484 return emitError () << " member index out of bounds" ;
24802485
2481- // FIXME(cir): Member type check is disabled for classes and incomplete types
2482- // as the codegen for these still need to be patched.
2483- if (!recordTy.isClass () && !recordTy. getBody () &&
2486+ // FIXME(cir): member type check is disabled for classes as the codegen for
2487+ // these still need to be patched.
2488+ if (!recordTy.isClass () &&
24842489 recordTy.getMembers ()[getIndex ()] != getResultTy ().getPointee ())
24852490 return emitError () << " member type mismatch" ;
24862491
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments