Skip to content

Commit

Permalink
[CIR][IR] Relax get_member verifier for incomplete types
Browse files Browse the repository at this point in the history
  • Loading branch information
gitoleg committed Sep 23, 2023
1 parent 73f8c46 commit 3e60e21
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,15 @@ 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.getBody();

return false;
}

//===----------------------------------------------------------------------===//
// GetMemberOp Definitions
//===----------------------------------------------------------------------===//
Expand All @@ -2410,18 +2419,19 @@ LogicalResult GetMemberOp::verify() {

// 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 (!recordTy.getBody())
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.
if (!recordTy.isClass() &&
recordTy.getMembers()[getIndex()] != getResultTy().getPointee())
if (!recordTy.isClass()
&& !isIncompleteType(recordTy.getMembers()[getIndex()])
&& recordTy.getMembers()[getIndex()] != getResultTy().getPointee())
return emitError() << "member type mismatch";

return mlir::success();
}

Expand Down

0 comments on commit 3e60e21

Please sign in to comment.