aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CIR/CodeGen')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenBuilder.h22
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp7
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenCXXABI.h5
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp23
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenClass.cpp8
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenExpr.cpp79
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp38
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp35
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenFunction.cpp13
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenFunction.h21
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp24
11 files changed, 225 insertions, 50 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index f855bda..73c9fb9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -408,21 +408,23 @@ public:
}
mlir::Value createSetBitfield(mlir::Location loc, mlir::Type resultType,
- mlir::Value dstAddr, mlir::Type storageType,
+ Address dstAddr, mlir::Type storageType,
mlir::Value src, const CIRGenBitFieldInfo &info,
- bool isLvalueVolatile, bool useVolatile) {
- return create<cir::SetBitfieldOp>(loc, resultType, dstAddr, storageType,
- src, info.name, info.size, info.offset,
- info.isSigned, isLvalueVolatile);
+ bool isLvalueVolatile) {
+ return create<cir::SetBitfieldOp>(
+ loc, resultType, dstAddr.getPointer(), storageType, src, info.name,
+ info.size, info.offset, info.isSigned, isLvalueVolatile,
+ dstAddr.getAlignment().getAsAlign().value());
}
mlir::Value createGetBitfield(mlir::Location loc, mlir::Type resultType,
- mlir::Value addr, mlir::Type storageType,
+ Address addr, mlir::Type storageType,
const CIRGenBitFieldInfo &info,
- bool isLvalueVolatile, bool useVolatile) {
- return create<cir::GetBitfieldOp>(loc, resultType, addr, storageType,
- info.name, info.size, info.offset,
- info.isSigned, isLvalueVolatile);
+ bool isLvalueVolatile) {
+ return create<cir::GetBitfieldOp>(
+ loc, resultType, addr.getPointer(), storageType, info.name, info.size,
+ info.offset, info.isSigned, isLvalueVolatile,
+ addr.getAlignment().getAsAlign().value());
}
};
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 61d1c54..ef136f8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -121,6 +121,13 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
return RValue::get(nullptr);
}
+ case Builtin::BI__builtin_assume_separate_storage: {
+ mlir::Value value0 = emitScalarExpr(e->getArg(0));
+ mlir::Value value1 = emitScalarExpr(e->getArg(1));
+ builder.create<cir::AssumeSepStorageOp>(loc, value0, value1);
+ return RValue::get(nullptr);
+ }
+
case Builtin::BI__builtin_complex: {
mlir::Value real = emitScalarExpr(e->getArg(0));
mlir::Value imag = emitScalarExpr(e->getArg(1));
diff --git a/clang/lib/CIR/CodeGen/CIRGenCXXABI.h b/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
index eb079b8..5929568 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
+++ b/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
@@ -75,6 +75,11 @@ public:
/// Emit dtor variants required by this ABI.
virtual void emitCXXDestructors(const clang::CXXDestructorDecl *d) = 0;
+ virtual void emitDestructorCall(CIRGenFunction &cgf,
+ const CXXDestructorDecl *dd, CXXDtorType type,
+ bool forVirtualBase, bool delegating,
+ Address thisAddr, QualType thisTy) = 0;
+
/// Returns true if the given destructor type should be emitted as a linkonce
/// delegating thunk, regardless of whether the dtor is defined in this TU or
/// not.
diff --git a/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp
index 8da832d..67d8988 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp
@@ -246,6 +246,29 @@ static void emitNewInitializer(CIRGenFunction &cgf, const CXXNewExpr *e,
}
}
+RValue CIRGenFunction::emitCXXDestructorCall(
+ GlobalDecl dtor, const CIRGenCallee &callee, mlir::Value thisVal,
+ QualType thisTy, mlir::Value implicitParam, QualType implicitParamTy,
+ const CallExpr *ce) {
+ const CXXMethodDecl *dtorDecl = cast<CXXMethodDecl>(dtor.getDecl());
+
+ assert(!thisTy.isNull());
+ assert(thisTy->getAsCXXRecordDecl() == dtorDecl->getParent() &&
+ "Pointer/Object mixup");
+
+ assert(!cir::MissingFeatures::addressSpace());
+
+ CallArgList args;
+ commonBuildCXXMemberOrOperatorCall(*this, dtorDecl, thisVal, implicitParam,
+ implicitParamTy, ce, args, nullptr);
+ assert((ce || dtor.getDecl()) && "expected source location provider");
+ assert(!cir::MissingFeatures::opCallMustTail());
+ return emitCall(cgm.getTypes().arrangeCXXStructorDeclaration(dtor), callee,
+ ReturnValueSlot(), args, nullptr,
+ ce ? getLoc(ce->getExprLoc())
+ : getLoc(dtor.getDecl()->getSourceRange()));
+}
+
/// Emit a call to an operator new or operator delete function, as implicitly
/// created by new-expressions and delete-expressions.
static RValue emitNewDeleteCall(CIRGenFunction &cgf,
diff --git a/clang/lib/CIR/CodeGen/CIRGenClass.cpp b/clang/lib/CIR/CodeGen/CIRGenClass.cpp
index 8667bb6..fbf53db 100644
--- a/clang/lib/CIR/CodeGen/CIRGenClass.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenClass.cpp
@@ -392,6 +392,14 @@ void CIRGenFunction::emitDelegatingCXXConstructorCall(
}
}
+void CIRGenFunction::emitCXXDestructorCall(const CXXDestructorDecl *dd,
+ CXXDtorType type,
+ bool forVirtualBase, bool delegating,
+ Address thisAddr, QualType thisTy) {
+ cgm.getCXXABI().emitDestructorCall(*this, dd, type, forVirtualBase,
+ delegating, thisAddr, thisTy);
+}
+
Address CIRGenFunction::getAddressOfBaseClass(
Address value, const CXXRecordDecl *derived,
llvm::iterator_range<CastExpr::path_const_iterator> path,
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 51da48d..1f64801 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -333,13 +333,12 @@ mlir::Value CIRGenFunction::emitStoreThroughBitfieldLValue(RValue src,
Address ptr = dst.getBitFieldAddress();
assert(!cir::MissingFeatures::armComputeVolatileBitfields());
- const bool useVolatile = false;
mlir::Value dstAddr = dst.getAddress().getPointer();
- return builder.createSetBitfield(dstAddr.getLoc(), resLTy, dstAddr,
+ return builder.createSetBitfield(dstAddr.getLoc(), resLTy, ptr,
ptr.getElementType(), src.getValue(), info,
- dst.isVolatileQualified(), useVolatile);
+ dst.isVolatileQualified());
}
RValue CIRGenFunction::emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc) {
@@ -352,8 +351,7 @@ RValue CIRGenFunction::emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc) {
assert(!cir::MissingFeatures::armComputeVolatileBitfields());
mlir::Value field = builder.createGetBitfield(
- getLoc(loc), resLTy, ptr.getPointer(), ptr.getElementType(), info,
- lv.isVolatile(), false);
+ getLoc(loc), resLTy, ptr, ptr.getElementType(), info, lv.isVolatile());
assert(!cir::MissingFeatures::opLoadEmitScalarRangeCheck() && "NYI");
return RValue::get(field);
}
@@ -366,7 +364,10 @@ Address CIRGenFunction::getAddrOfBitFieldStorage(LValue base,
cir::PointerType fieldPtr = cir::PointerType::get(fieldType);
cir::GetMemberOp sea = getBuilder().createGetMember(
loc, fieldPtr, base.getPointer(), field->getName(), index);
- return Address(sea, CharUnits::One());
+ auto rec = cast<cir::RecordType>(base.getAddress().getElementType());
+ CharUnits offset = CharUnits::fromQuantity(
+ rec.getElementOffset(cgm.getDataLayout().layout, index));
+ return Address(sea, base.getAlignment().alignmentAtOffset(offset));
}
LValue CIRGenFunction::emitLValueForBitField(LValue base,
@@ -662,7 +663,8 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) {
}
case UO_PreInc:
case UO_PreDec: {
- bool isInc = e->isIncrementOp();
+ cir::UnaryOpKind kind =
+ e->isIncrementOp() ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
LValue lv = emitLValue(e->getSubExpr());
assert(e->isPrefix() && "Prefix operator in unexpected state!");
@@ -671,7 +673,7 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) {
cgm.errorNYI(e->getSourceRange(), "UnaryOp complex inc/dec");
lv = LValue();
} else {
- emitScalarPrePostIncDec(e, lv, isInc, /*isPre=*/true);
+ emitScalarPrePostIncDec(e, lv, kind, /*isPre=*/true);
}
return lv;
@@ -1053,6 +1055,67 @@ LValue CIRGenFunction::emitMemberExpr(const MemberExpr *e) {
llvm_unreachable("Unhandled member declaration!");
}
+/// Evaluate an expression into a given memory location.
+void CIRGenFunction::emitAnyExprToMem(const Expr *e, Address location,
+ Qualifiers quals, bool isInit) {
+ // FIXME: This function should take an LValue as an argument.
+ switch (getEvaluationKind(e->getType())) {
+ case cir::TEK_Complex: {
+ LValue lv = makeAddrLValue(location, e->getType());
+ emitComplexExprIntoLValue(e, lv, isInit);
+ return;
+ }
+
+ case cir::TEK_Aggregate: {
+ emitAggExpr(e, AggValueSlot::forAddr(location, quals,
+ AggValueSlot::IsDestructed_t(isInit),
+ AggValueSlot::IsAliased_t(!isInit),
+ AggValueSlot::MayOverlap));
+ return;
+ }
+
+ case cir::TEK_Scalar: {
+ RValue rv = RValue::get(emitScalarExpr(e));
+ LValue lv = makeAddrLValue(location, e->getType());
+ emitStoreThroughLValue(rv, lv);
+ return;
+ }
+ }
+
+ llvm_unreachable("bad evaluation kind");
+}
+
+LValue CIRGenFunction::emitCompoundLiteralLValue(const CompoundLiteralExpr *e) {
+ if (e->isFileScope()) {
+ cgm.errorNYI(e->getSourceRange(), "emitCompoundLiteralLValue: FileScope");
+ return {};
+ }
+
+ if (e->getType()->isVariablyModifiedType()) {
+ cgm.errorNYI(e->getSourceRange(),
+ "emitCompoundLiteralLValue: VariablyModifiedType");
+ return {};
+ }
+
+ Address declPtr = createMemTemp(e->getType(), getLoc(e->getSourceRange()),
+ ".compoundliteral");
+ const Expr *initExpr = e->getInitializer();
+ LValue result = makeAddrLValue(declPtr, e->getType(), AlignmentSource::Decl);
+
+ emitAnyExprToMem(initExpr, declPtr, e->getType().getQualifiers(),
+ /*Init*/ true);
+
+ // Block-scope compound literals are destroyed at the end of the enclosing
+ // scope in C.
+ if (!getLangOpts().CPlusPlus && e->getType().isDestructedType()) {
+ cgm.errorNYI(e->getSourceRange(),
+ "emitCompoundLiteralLValue: non C++ DestructedType");
+ return {};
+ }
+
+ return result;
+}
+
LValue CIRGenFunction::emitCallExprLValue(const CallExpr *e) {
RValue rv = emitCallExpr(e);
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 0a22771..6756a7c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -52,28 +52,33 @@ public:
mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *e);
mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e);
mlir::Value VisitInitListExpr(const InitListExpr *e);
+
+ mlir::Value VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
+ return emitLoadOfLValue(e);
+ }
+
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
mlir::Value VisitParenExpr(ParenExpr *e);
mlir::Value
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e);
- mlir::Value VisitPrePostIncDec(const UnaryOperator *e, bool isInc,
+ mlir::Value VisitPrePostIncDec(const UnaryOperator *e, cir::UnaryOpKind op,
bool isPre);
mlir::Value VisitUnaryPostDec(const UnaryOperator *e) {
- return VisitPrePostIncDec(e, false, false);
+ return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, false);
}
mlir::Value VisitUnaryPostInc(const UnaryOperator *e) {
- return VisitPrePostIncDec(e, true, false);
+ return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, false);
}
mlir::Value VisitUnaryPreDec(const UnaryOperator *e) {
- return VisitPrePostIncDec(e, false, true);
+ return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, true);
}
mlir::Value VisitUnaryPreInc(const UnaryOperator *e) {
- return VisitPrePostIncDec(e, true, true);
+ return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, true);
}
mlir::Value VisitUnaryDeref(const Expr *e);
@@ -355,9 +360,10 @@ mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
}
mlir::Value ComplexExprEmitter::VisitPrePostIncDec(const UnaryOperator *e,
- bool isInc, bool isPre) {
+ cir::UnaryOpKind op,
+ bool isPre) {
LValue lv = cgf.emitLValue(e->getSubExpr());
- return cgf.emitComplexPrePostIncDec(e, lv, isInc, isPre);
+ return cgf.emitComplexPrePostIncDec(e, lv, op, isPre);
}
mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) {
@@ -449,12 +455,15 @@ mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) {
}
mlir::Value CIRGenFunction::emitComplexPrePostIncDec(const UnaryOperator *e,
- LValue lv, bool isInc,
+ LValue lv,
+ cir::UnaryOpKind op,
bool isPre) {
+ assert(op == cir::UnaryOpKind::Inc ||
+ op == cir::UnaryOpKind::Dec && "Invalid UnaryOp kind for ComplexType");
+
mlir::Value inVal = emitLoadOfComplex(lv, e->getExprLoc());
mlir::Location loc = getLoc(e->getExprLoc());
- auto opKind = isInc ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
- mlir::Value incVal = builder.createUnaryOp(loc, opKind, inVal);
+ mlir::Value incVal = builder.createUnaryOp(loc, op, inVal);
// Store the updated result through the lvalue.
emitStoreOfComplex(loc, incVal, lv, /*isInit=*/false);
@@ -467,6 +476,15 @@ mlir::Value CIRGenFunction::emitComplexPrePostIncDec(const UnaryOperator *e,
return isPre ? incVal : inVal;
}
+void CIRGenFunction::emitComplexExprIntoLValue(const Expr *e, LValue dest,
+ bool isInit) {
+ assert(e && getComplexType(e->getType()) &&
+ "Invalid complex expression to emit");
+ ComplexExprEmitter emitter(*this);
+ mlir::Value value = emitter.Visit(const_cast<Expr *>(e));
+ emitter.emitStoreOfComplex(getLoc(e->getExprLoc()), value, dest, isInit);
+}
+
mlir::Value CIRGenFunction::emitLoadOfComplex(LValue src, SourceLocation loc) {
return ComplexExprEmitter(*this).emitLoadOfLValue(src, loc);
}
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 9e13b4c..eba6bff 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -233,6 +233,10 @@ public:
mlir::Value VisitMemberExpr(MemberExpr *e);
+ mlir::Value VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
+ return emitLoadOfLValue(e);
+ }
+
mlir::Value VisitInitListExpr(InitListExpr *e);
mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
@@ -383,22 +387,22 @@ public:
// Unary Operators.
mlir::Value VisitUnaryPostDec(const UnaryOperator *e) {
LValue lv = cgf.emitLValue(e->getSubExpr());
- return emitScalarPrePostIncDec(e, lv, false, false);
+ return emitScalarPrePostIncDec(e, lv, cir::UnaryOpKind::Dec, false);
}
mlir::Value VisitUnaryPostInc(const UnaryOperator *e) {
LValue lv = cgf.emitLValue(e->getSubExpr());
- return emitScalarPrePostIncDec(e, lv, true, false);
+ return emitScalarPrePostIncDec(e, lv, cir::UnaryOpKind::Inc, false);
}
mlir::Value VisitUnaryPreDec(const UnaryOperator *e) {
LValue lv = cgf.emitLValue(e->getSubExpr());
- return emitScalarPrePostIncDec(e, lv, false, true);
+ return emitScalarPrePostIncDec(e, lv, cir::UnaryOpKind::Dec, true);
}
mlir::Value VisitUnaryPreInc(const UnaryOperator *e) {
LValue lv = cgf.emitLValue(e->getSubExpr());
- return emitScalarPrePostIncDec(e, lv, true, true);
+ return emitScalarPrePostIncDec(e, lv, cir::UnaryOpKind::Inc, true);
}
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv,
- bool isInc, bool isPre) {
+ cir::UnaryOpKind kind, bool isPre) {
if (cgf.getLangOpts().OpenMP)
cgf.cgm.errorNYI(e->getSourceRange(), "inc/dec OpenMP");
@@ -427,7 +431,7 @@ public:
// -> bool = ((int)bool + 1 != 0)
// An interesting aspect of this is that increment is always true.
// Decrement does not have this property.
- if (isInc && type->isBooleanType()) {
+ if (kind == cir::UnaryOpKind::Inc && type->isBooleanType()) {
value = builder.getTrue(cgf.getLoc(e->getExprLoc()));
} else if (type->isIntegerType()) {
QualType promotedType;
@@ -458,7 +462,7 @@ public:
assert(!cir::MissingFeatures::sanitizers());
if (e->canOverflow() && type->isSignedIntegerOrEnumerationType()) {
- value = emitIncDecConsiderOverflowBehavior(e, value, isInc);
+ value = emitIncDecConsiderOverflowBehavior(e, value, kind);
} else {
cir::UnaryOpKind kind =
e->isIncrementOp() ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
@@ -480,7 +484,7 @@ public:
// For everything else, we can just do a simple increment.
mlir::Location loc = cgf.getLoc(e->getSourceRange());
CIRGenBuilderTy &builder = cgf.getBuilder();
- int amount = (isInc ? 1 : -1);
+ int amount = kind == cir::UnaryOpKind::Inc ? 1 : -1;
mlir::Value amt = builder.getSInt32(amount, loc);
assert(!cir::MissingFeatures::sanitizers());
value = builder.createPtrStride(loc, value, amt);
@@ -500,8 +504,8 @@ public:
if (mlir::isa<cir::SingleType, cir::DoubleType>(value.getType())) {
// Create the inc/dec operation.
// NOTE(CIR): clang calls CreateAdd but folds this to a unary op
- cir::UnaryOpKind kind =
- (isInc ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec);
+ assert(kind == cir::UnaryOpKind::Inc ||
+ kind == cir::UnaryOpKind::Dec && "Invalid UnaryOp kind");
value = emitUnaryOp(e, kind, value);
} else {
cgf.cgm.errorNYI(e->getSourceRange(), "Unary inc/dec other fp type");
@@ -532,9 +536,9 @@ public:
mlir::Value emitIncDecConsiderOverflowBehavior(const UnaryOperator *e,
mlir::Value inVal,
- bool isInc) {
- cir::UnaryOpKind kind =
- e->isIncrementOp() ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
+ cir::UnaryOpKind kind) {
+ assert(kind == cir::UnaryOpKind::Inc ||
+ kind == cir::UnaryOpKind::Dec && "Invalid UnaryOp kind");
switch (cgf.getLangOpts().getSignedOverflowBehavior()) {
case LangOptions::SOB_Defined:
return emitUnaryOp(e, kind, inVal, /*nsw=*/false);
@@ -2147,8 +2151,9 @@ mlir::Value ScalarExprEmitter::VisitAbstractConditionalOperator(
}
mlir::Value CIRGenFunction::emitScalarPrePostIncDec(const UnaryOperator *e,
- LValue lv, bool isInc,
+ LValue lv,
+ cir::UnaryOpKind kind,
bool isPre) {
return ScalarExprEmitter(*this, builder)
- .emitScalarPrePostIncDec(e, lv, isInc, isPre);
+ .emitScalarPrePostIncDec(e, lv, kind, isPre);
}
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index e532b9d..3e69e56 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -593,11 +593,12 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &args) {
assert(!cir::MissingFeatures::dtorCleanups());
- // TODO(cir): A complete destructor is supposed to call the base destructor.
- // Since we have to emit both dtor kinds we just fall through for now and.
- // As long as we don't support virtual bases this should be functionally
- // equivalent.
- assert(!cir::MissingFeatures::completeDtors());
+ if (!isTryBody) {
+ QualType thisTy = dtor->getFunctionObjectParameterType();
+ emitCXXDestructorCall(dtor, Dtor_Base, /*forVirtualBase=*/false,
+ /*delegating=*/false, loadCXXThisAddress(), thisTy);
+ break;
+ }
// Fallthrough: act like we're in the base variant.
[[fallthrough]];
@@ -698,6 +699,8 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
return emitStringLiteralLValue(cast<StringLiteral>(e));
case Expr::MemberExprClass:
return emitMemberExpr(cast<MemberExpr>(e));
+ case Expr::CompoundLiteralExprClass:
+ return emitCompoundLiteralLValue(cast<CompoundLiteralExpr>(e));
case Expr::BinaryOperatorClass:
return emitBinaryOperatorLValue(cast<BinaryOperator>(e));
case Expr::CompoundAssignOperatorClass: {
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index 9541f4f..2aceeef 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -757,6 +757,11 @@ public:
RValue emitAnyExpr(const clang::Expr *e,
AggValueSlot aggSlot = AggValueSlot::ignored());
+ /// Emits the code necessary to evaluate an arbitrary expression into the
+ /// given memory location.
+ void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals,
+ bool isInitializer);
+
/// Similarly to emitAnyExpr(), however, the result will always be accessible
/// even if no aggregate location is provided.
RValue emitAnyExprToTemp(const clang::Expr *e);
@@ -828,6 +833,7 @@ public:
mlir::Value emitCheckedArgForAssume(const Expr *e);
LValue emitCompoundAssignmentLValue(const clang::CompoundAssignOperator *e);
+ LValue emitCompoundLiteralLValue(const CompoundLiteralExpr *e);
void emitConstructorBody(FunctionArgList &args);
void emitDestructorBody(FunctionArgList &args);
@@ -847,6 +853,15 @@ public:
bool delegating, Address thisAddr,
CallArgList &args, clang::SourceLocation loc);
+ void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type,
+ bool forVirtualBase, bool delegating,
+ Address thisAddr, QualType thisTy);
+
+ RValue emitCXXDestructorCall(GlobalDecl dtor, const CIRGenCallee &callee,
+ mlir::Value thisVal, QualType thisTy,
+ mlir::Value implicitParam,
+ QualType implicitParamTy, const CallExpr *e);
+
mlir::LogicalResult emitCXXForRangeStmt(const CXXForRangeStmt &s,
llvm::ArrayRef<const Attr *> attrs);
@@ -911,7 +926,7 @@ public:
mlir::Value emitScalarExpr(const clang::Expr *e);
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv,
- bool isInc, bool isPre);
+ cir::UnaryOpKind kind, bool isPre);
/// Build a debug stoppoint if we are emitting debug info.
void emitStopPoint(const Stmt *s);
@@ -930,8 +945,10 @@ public:
/// returning the result.
mlir::Value emitComplexExpr(const Expr *e);
+ void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit);
+
mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv,
- bool isInc, bool isPre);
+ cir::UnaryOpKind op, bool isPre);
LValue emitComplexAssignmentLValue(const BinaryOperator *e);
diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
index 1496d87..6577f5f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
@@ -46,6 +46,11 @@ public:
void emitCXXDestructors(const clang::CXXDestructorDecl *d) override;
void emitCXXStructor(clang::GlobalDecl gd) override;
+ void emitDestructorCall(CIRGenFunction &cgf, const CXXDestructorDecl *dd,
+ CXXDtorType type, bool forVirtualBase,
+ bool delegating, Address thisAddr,
+ QualType thisTy) override;
+
bool useThunkForDtorVariant(const CXXDestructorDecl *dtor,
CXXDtorType dt) const override {
// Itanium does not emit any destructor variant as an inline thunk.
@@ -240,6 +245,25 @@ bool CIRGenItaniumCXXABI::needsVTTParameter(GlobalDecl gd) {
return false;
}
+void CIRGenItaniumCXXABI::emitDestructorCall(
+ CIRGenFunction &cgf, const CXXDestructorDecl *dd, CXXDtorType type,
+ bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy) {
+ GlobalDecl gd(dd, type);
+ if (needsVTTParameter(gd)) {
+ cgm.errorNYI(dd->getSourceRange(), "emitDestructorCall: VTT");
+ }
+
+ mlir::Value vtt = nullptr;
+ ASTContext &astContext = cgm.getASTContext();
+ QualType vttTy = astContext.getPointerType(astContext.VoidPtrTy);
+ assert(!cir::MissingFeatures::appleKext());
+ CIRGenCallee callee =
+ CIRGenCallee::forDirect(cgm.getAddrOfCXXStructor(gd), gd);
+
+ cgf.emitCXXDestructorCall(gd, callee, thisAddr.getPointer(), thisTy, vtt,
+ vttTy, nullptr);
+}
+
CIRGenCXXABI *clang::CIRGen::CreateCIRGenItaniumCXXABI(CIRGenModule &cgm) {
switch (cgm.getASTContext().getCXXABIKind()) {
case TargetCXXABI::GenericItanium: