Skip to content

Commit 2dc6f86

Browse files
andykaylorlanza
authored andcommitted
[CIR] Treat cir.record class and struct types equivalently. (llvm#1564)
When we create a `cir.record` type, we track the `RecordKind` according to whether the source code declared the type using `struct` or `class` even though these are semantically equivalent. The distinction is used in naming the type when we lower to the LLVM dialect. This change updates the code to remove the last place where we were handling class and struct records differently.
1 parent f8b56e8 commit 2dc6f86

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,10 +3610,7 @@ LogicalResult cir::GetMemberOp::verify() {
36103610
if (recordTy.getMembers().size() <= getIndex())
36113611
return emitError() << "member index out of bounds";
36123612

3613-
// FIXME(cir): member type check is disabled for classes as the codegen for
3614-
// these still need to be patched.
3615-
if (!recordTy.isClass() &&
3616-
recordTy.getMembers()[getIndex()] != getResultTy().getPointee())
3613+
if (recordTy.getMembers()[getIndex()] != getResultTy().getPointee())
36173614
return emitError() << "member type mismatch";
36183615

36193616
return mlir::success();

clang/test/CIR/IR/getmember.cir

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
!u16i = !cir.int<u, 16>
55
!u32i = !cir.int<u, 32>
66

7-
!ty_Class = !cir.record<class "Class" {!u16i, !u32i}>
8-
!ty_Incomplete = !cir.record<struct "Incomplete" incomplete>
97
!ty_Struct = !cir.record<struct "Struct" {!u16i, !u32i}>
108

119
module {
@@ -14,11 +12,4 @@ module {
1412
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_Struct> -> !cir.ptr<!u32i>
1513
cir.return
1614
}
17-
18-
// FIXME: remove bypass once codegen for CIR class records is patched.
19-
cir.func @shouldBypassMemberTypeCheckForClassRecords(%arg0 : !cir.ptr<!ty_Class>) {
20-
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_Class> -> !cir.ptr<!cir.ptr<!u32i>>
21-
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_Class> -> !cir.ptr<!cir.ptr<!u32i>>
22-
cir.return
23-
}
2415
}

0 commit comments

Comments
 (0)