diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp index 94c41aab2280..f383c42a1d45 100644 --- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp @@ -284,6 +284,12 @@ class CIRGenItaniumCXXABI : public cir::CIRGenCXXABI { void buildBadCastCall(CIRGenFunction &CGF, mlir::Location loc) override; + // The traditional clang CodeGen emits calls to `__dynamic_cast` directly into + // LLVM in the `emitDynamicCastCall` function. In CIR, `dynamic_cast` + // expressions are lowered to `cir.dyn_cast` ops instead of calls to runtime + // functions. So during CIRGen we don't need the `emitDynamicCastCall` + // function that clang CodeGen has. + mlir::cir::DynamicCastInfoAttr buildDynamicCastInfo(CIRGenFunction &CGF, mlir::Location Loc, QualType SrcRecordTy, QualType DestRecordTy) override; diff --git a/clang/lib/CIR/Dialect/IR/MissingFeatures.h b/clang/lib/CIR/Dialect/IR/MissingFeatures.h index b7ae4873ee1a..e21fc0e0b191 100644 --- a/clang/lib/CIR/Dialect/IR/MissingFeatures.h +++ b/clang/lib/CIR/Dialect/IR/MissingFeatures.h @@ -20,9 +20,13 @@ namespace cir { struct MissingFeatures { // C++ ABI support static bool cxxABI() { return false; } + static bool setCallingConv() { return false; } + + // Address space related + static bool addressSpace() { return false; } // Sanitizers - static bool sanitizers() { return false; } + static bool buildTypeCheck() { return false; } }; } // namespace cir diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.cpp index 1c9b1f1b5f8f..3619648056cc 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.cpp @@ -39,6 +39,8 @@ LoweringPrepareCXXABI *LoweringPrepareCXXABI::createItaniumABI() { static void buildBadCastCall(CIRBaseBuilderTy &builder, mlir::Location loc, mlir::FlatSymbolRefAttr badCastFuncRef) { // TODO(cir): set the calling convention to __cxa_bad_cast. + assert(!MissingFeatures::setCallingConv()); + builder.create(loc, badCastFuncRef, mlir::ValueRange{}); builder.create(loc); builder.clearInsertionPoint(); @@ -51,6 +53,8 @@ static mlir::Value buildDynamicCastAfterNullCheck(CIRBaseBuilderTy &builder, auto castInfo = op.getInfo().cast(); // TODO(cir): consider address space + assert(!MissingFeatures::addressSpace()); + auto srcPtr = builder.createBitcast(srcValue, builder.getVoidPtrTy()); auto srcRtti = builder.getConstant(loc, castInfo.getSrcRtti()); auto destRtti = builder.getConstant(loc, castInfo.getDestRtti()); @@ -58,7 +62,9 @@ static mlir::Value buildDynamicCastAfterNullCheck(CIRBaseBuilderTy &builder, auto dynCastFuncRef = castInfo.getRuntimeFunc(); mlir::Value dynCastFuncArgs[4] = {srcPtr, srcRtti, destRtti, offsetHint}; + // TODO(cir): set the calling convention for __dynamic_cast. + assert(!MissingFeatures::setCallingConv()); mlir::Value castedPtr = builder .create(loc, dynCastFuncRef, @@ -90,11 +96,7 @@ LoweringPrepareItaniumCXXABI::lowerDynamicCast(CIRBaseBuilderTy &builder, auto loc = op->getLoc(); auto srcValue = op.getSrc(); - // TODO: emit a sanitizer check. - // buildTypeCheck( - // TCK_DynamicOperation, DCE->getExprLoc(), - // ThisAddr.getPointer(), srcRecordTy) - assert(!MissingFeatures::sanitizers()); + assert(!MissingFeatures::buildTypeCheck()); if (op.isRefcast()) return buildDynamicCastAfterNullCheck(builder, op);