Skip to content

Commit b075ba3

Browse files
gitoleglanza
authored andcommitted
[CIR][IR] Harden get_member verifier (llvm#330)
I think it's time to claim that CIR supports recursive types (many thanks to llvm#303 and to @sitio-couto :) ) And we can bring back the `get_member` verification back, with no checks for incomplete types. What do you think? And we can close llvm#256 as well
1 parent 48777f9 commit b075ba3

File tree

2 files changed

+1
-25
lines changed

2 files changed

+1
-25
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,14 +2423,6 @@ LogicalResult MemCpyOp::verify() {
24232423
return mlir::success();
24242424
}
24252425

2426-
static bool isIncompleteType(mlir::Type typ) {
2427-
if (auto ptr = typ.dyn_cast<PointerType>())
2428-
return isIncompleteType(ptr.getPointee());
2429-
else if (auto rec = typ.dyn_cast<StructType>())
2430-
return rec.isIncomplete();
2431-
return false;
2432-
}
2433-
24342426
//===----------------------------------------------------------------------===//
24352427
// GetMemberOp Definitions
24362428
//===----------------------------------------------------------------------===//
@@ -2441,21 +2433,12 @@ LogicalResult GetMemberOp::verify() {
24412433
if (!recordTy)
24422434
return emitError() << "expected pointer to a record type";
24432435

2444-
// FIXME: currently we bypass typechecking of incomplete types due to errors
2445-
// in the codegen process. This should be removed once the codegen is fixed.
2446-
if (isIncompleteType(recordTy))
2447-
return mlir::success();
2448-
24492436
if (recordTy.getMembers().size() <= getIndex())
24502437
return emitError() << "member index out of bounds";
24512438

24522439
// FIXME(cir): member type check is disabled for classes as the codegen for
24532440
// these still need to be patched.
2454-
// Also we bypass the typechecking for the fields of incomplete types.
2455-
bool shouldSkipMemberTypeMismatch =
2456-
recordTy.isClass() || isIncompleteType(recordTy.getMembers()[getIndex()]);
2457-
2458-
if (!shouldSkipMemberTypeMismatch
2441+
if (!recordTy.isClass()
24592442
&& recordTy.getMembers()[getIndex()] != getResultTy().getPointee())
24602443
return emitError() << "member type mismatch";
24612444

clang/test/CIR/IR/getmember.cir

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ module {
1515
cir.return
1616
}
1717

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-
2518
// FIXME: remove bypass once codegen for CIR class records is patched.
2619
cir.func @shouldBypassMemberTypeCheckForClassRecords(%arg0 : !cir.ptr<!ty_22Class22>) {
2720
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Class22> -> !cir.ptr<!cir.ptr<!u32i>>

0 commit comments

Comments
 (0)