From 0e148f81c74f3387d5cee62875c58456c66f8400 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Wed, 22 Nov 2023 22:54:17 +0300 Subject: [PATCH] [CIR][IR] Harden get_member verifier (#330) I think it's time to claim that CIR supports recursive types (many thanks to #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 #256 as well --- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 19 +------------------ clang/test/CIR/IR/getmember.cir | 7 ------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 726516732c6e52..8fcc8c472ac2c2 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2423,14 +2423,6 @@ 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.isIncomplete(); - return false; -} - //===----------------------------------------------------------------------===// // GetMemberOp Definitions //===----------------------------------------------------------------------===// @@ -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"; diff --git a/clang/test/CIR/IR/getmember.cir b/clang/test/CIR/IR/getmember.cir index 932e4a5b29f5d8..5bfd8f24d16113 100644 --- a/clang/test/CIR/IR/getmember.cir +++ b/clang/test/CIR/IR/getmember.cir @@ -15,13 +15,6 @@ module { cir.return } - // FIXME: remove bypass once codegen for CIR records is patched. - cir.func @shouldBypassMemberIndexCheckForIncompleteRecords(%arg0 : !cir.ptr) { - // CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr -> !cir.ptr - %0 = cir.get_member %arg0[1] {name = "test"} : !cir.ptr -> !cir.ptr - cir.return - } - // FIXME: remove bypass once codegen for CIR class records is patched. cir.func @shouldBypassMemberTypeCheckForClassRecords(%arg0 : !cir.ptr) { // CHECK: cir.get_member %arg0[1] {name = "test"} : !cir.ptr -> !cir.ptr>