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 @@ -2461,12 +2461,17 @@ LogicalResult GetMemberOp::verify() {
2461
2461
if (!recordTy)
2462
2462
return emitError () << " expected pointer to a record type" ;
2463
2463
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
+
2464
2469
if (recordTy.getMembers ().size () <= getIndex ())
2465
2470
return emitError () << " member index out of bounds" ;
2466
2471
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 () &&
2470
2475
recordTy.getMembers ()[getIndex ()] != getResultTy ().getPointee ())
2471
2476
return emitError () << " member type mismatch" ;
2472
2477
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 {
522
522
cir.throw(%11 : !cir.ptr<!cir.ptr<!u8i>>) // expected-error {{'type_info' symbol attribute missing}}
523
523
}
524
524
}
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