From 3e60e21dcd7164836ff24be1bd26ec09a8f3e858 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Sat, 23 Sep 2023 14:11:08 +0300 Subject: [PATCH] [CIR][IR] Relax get_member verifier for incomplete types --- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 48fe9bc43c1b..f2b80aab7e8e 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2398,6 +2398,15 @@ LogicalResult MemCpyOp::verify() { return mlir::success(); } +static bool isIncompleteType(mlir::Type typ) { + if (auto ptr = typ.dyn_cast()) + return isIncompleteType(ptr.getPointee()); + else if (auto rec = typ.dyn_cast()) + return !rec.getBody(); + + return false; +} + //===----------------------------------------------------------------------===// // GetMemberOp Definitions //===----------------------------------------------------------------------===// @@ -2410,7 +2419,7 @@ 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()) @@ -2418,10 +2427,11 @@ LogicalResult GetMemberOp::verify() { // 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(); }