Skip to content

Commit

Permalink
Fix some nits as commented in the reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancern committed Apr 18, 2024
1 parent bbce3b9 commit 3fef0fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/CIR/Dialect/IR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<mlir::cir::CallOp>(loc, badCastFuncRef, mlir::ValueRange{});
builder.create<mlir::cir::UnreachableOp>(loc);
builder.clearInsertionPoint();
Expand All @@ -51,14 +53,18 @@ static mlir::Value buildDynamicCastAfterNullCheck(CIRBaseBuilderTy &builder,
auto castInfo = op.getInfo().cast<mlir::cir::DynamicCastInfoAttr>();

// 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());
auto offsetHint = builder.getConstant(loc, castInfo.getOffsetHint());

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<mlir::cir::CallOp>(loc, dynCastFuncRef,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3fef0fa

Please sign in to comment.