Skip to content

Commit

Permalink
[CIR][IR] Harden get_member verifier (llvm#330)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitoleg authored and lanza committed Jun 20, 2024
1 parent 60a1cb1 commit 0e148f8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
19 changes: 1 addition & 18 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2423,14 +2423,6 @@ LogicalResult MemCpyOp::verify() {
return mlir::success();
}

static bool isIncompleteType(mlir::Type typ) {
if (auto ptr = typ.dyn_cast<PointerType>())
return isIncompleteType(ptr.getPointee());
else if (auto rec = typ.dyn_cast<StructType>())
return rec.isIncomplete();
return false;
}

//===----------------------------------------------------------------------===//
// GetMemberOp Definitions
//===----------------------------------------------------------------------===//
Expand All @@ -2441,21 +2433,12 @@ LogicalResult GetMemberOp::verify() {
if (!recordTy)
return emitError() << "expected pointer to a record type";

// FIXME: currently we bypass typechecking of incomplete types due to errors
// in the codegen process. This should be removed once the codegen is fixed.
if (isIncompleteType(recordTy))
return mlir::success();

if (recordTy.getMembers().size() <= getIndex())
return emitError() << "member index out of bounds";

// FIXME(cir): member type check is disabled for classes as the codegen for
// these still need to be patched.
// Also we bypass the typechecking for the fields of incomplete types.
bool shouldSkipMemberTypeMismatch =
recordTy.isClass() || isIncompleteType(recordTy.getMembers()[getIndex()]);

if (!shouldSkipMemberTypeMismatch
if (!recordTy.isClass()
&& recordTy.getMembers()[getIndex()] != getResultTy().getPointee())
return emitError() << "member type mismatch";

Expand Down
7 changes: 0 additions & 7 deletions clang/test/CIR/IR/getmember.cir
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ module {
cir.return
}

// FIXME: remove bypass once codegen for CIR records is patched.
cir.func @shouldBypassMemberIndexCheckForIncompleteRecords(%arg0 : !cir.ptr<!ty_22Incomplete22>) {
// CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Incomplete22> -> !cir.ptr<!u32i>
%0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr<!ty_22Incomplete22> -> !cir.ptr<!u32i>
cir.return
}

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

0 comments on commit 0e148f8

Please sign in to comment.