[clang] [CIR] Upstream support for calling constructors (PR #143579)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 10 11:19:03 PDT 2025
================
@@ -63,3 +66,74 @@ Address CIRGenFunction::getAddressOfBaseClass(
return value;
}
+
+void CIRGenFunction::emitCXXConstructorCall(const clang::CXXConstructorDecl *d,
+ clang::CXXCtorType type,
+ bool forVirtualBase,
+ bool delegating,
+ AggValueSlot thisAVS,
+ const clang::CXXConstructExpr *e) {
+ CallArgList args;
+ Address thisAddr = thisAVS.getAddress();
+ QualType thisType = d->getThisType();
+ mlir::Value thisPtr = thisAddr.getPointer();
+
+ assert(!cir::MissingFeatures::addressSpace());
+
+ args.add(RValue::get(thisPtr), thisType);
+
+ // In LLVM Codegen: If this is a trivial constructor, just emit what's needed.
+ // If this is a union copy constructor, we must emit a memcpy, because the AST
+ // does not model that copy.
+ assert(!cir::MissingFeatures::isMemcpyEquivalentSpecialMember());
+
+ const FunctionProtoType *fpt = d->getType()->castAs<FunctionProtoType>();
+
+ assert(!cir::MissingFeatures::opCallArgEvaluationOrder());
+
+ emitCallArgs(args, fpt, e->arguments(), e->getConstructor(),
+ /*ParamsToSkip=*/0);
+
+ assert(!cir::MissingFeatures::sanitizers());
+ emitCXXConstructorCall(d, type, forVirtualBase, delegating, thisAddr, args,
+ e->getExprLoc());
+}
+
+void CIRGenFunction::emitCXXConstructorCall(
+ const CXXConstructorDecl *d, CXXCtorType type, bool forVirtualBase,
+ bool delegating, Address thisAddr, CallArgList &args, SourceLocation loc) {
+
+ const auto *cd = d->getParent();
+
+ // If this is a call to a trivial default constructor:
+ // In LLVM: do nothing.
+ // In CIR: emit as a regular call, other later passes should lower the
+ // ctor call into trivial initialization.
+ assert(!cir::MissingFeatures::isTrivialCtorOrDtor());
+
+ assert(!cir::MissingFeatures::isMemcpyEquivalentSpecialMember());
+
+ bool passPrototypeArgs = true;
----------------
erichkeane wrote:
Read, but never set?
https://github.com/llvm/llvm-project/pull/143579
More information about the cfe-commits
mailing list