aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
diff options
context:
space:
mode:
authorAndy Kaylor <akaylor@nvidia.com>2025-06-27 16:56:26 -0700
committerGitHub <noreply@github.com>2025-06-27 16:56:26 -0700
commit32180cf9f9eb921a793bb208cf3bbfb1b86ee2ae (patch)
tree77f03a9f1add275cdb435dc8fa6fba7afff47241 /clang/lib/CIR/CodeGen/CIRGenFunction.cpp
parent570b95218c138573dd02f82f6f85856cb019dddf (diff)
downloadllvm-32180cf9f9eb921a793bb208cf3bbfb1b86ee2ae.zip
llvm-32180cf9f9eb921a793bb208cf3bbfb1b86ee2ae.tar.gz
llvm-32180cf9f9eb921a793bb208cf3bbfb1b86ee2ae.tar.bz2
[CIR] Upstream support for operator assign (#145979)
This adds support for assignment operators, including implicit operator definitions.
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenFunction.cpp')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenFunction.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index c029853..c4efabd 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -462,21 +462,23 @@ cir::FuncOp CIRGenFunction::generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
startFunction(gd, retTy, fn, funcType, args, loc, bodyRange.getBegin());
- if (isa<CXXDestructorDecl>(funcDecl))
+ if (isa<CXXDestructorDecl>(funcDecl)) {
getCIRGenModule().errorNYI(bodyRange, "C++ destructor definition");
- else if (isa<CXXConstructorDecl>(funcDecl))
+ } else if (isa<CXXConstructorDecl>(funcDecl)) {
emitConstructorBody(args);
- else if (getLangOpts().CUDA && !getLangOpts().CUDAIsDevice &&
- funcDecl->hasAttr<CUDAGlobalAttr>())
+ } else if (getLangOpts().CUDA && !getLangOpts().CUDAIsDevice &&
+ funcDecl->hasAttr<CUDAGlobalAttr>()) {
getCIRGenModule().errorNYI(bodyRange, "CUDA kernel");
- else if (isa<CXXMethodDecl>(funcDecl) &&
- cast<CXXMethodDecl>(funcDecl)->isLambdaStaticInvoker())
+ } else if (isa<CXXMethodDecl>(funcDecl) &&
+ cast<CXXMethodDecl>(funcDecl)->isLambdaStaticInvoker()) {
getCIRGenModule().errorNYI(bodyRange, "Lambda static invoker");
- else if (funcDecl->isDefaulted() && isa<CXXMethodDecl>(funcDecl) &&
- (cast<CXXMethodDecl>(funcDecl)->isCopyAssignmentOperator() ||
- cast<CXXMethodDecl>(funcDecl)->isMoveAssignmentOperator()))
- getCIRGenModule().errorNYI(bodyRange, "Default assignment operator");
- else if (body) {
+ } else if (funcDecl->isDefaulted() && isa<CXXMethodDecl>(funcDecl) &&
+ (cast<CXXMethodDecl>(funcDecl)->isCopyAssignmentOperator() ||
+ cast<CXXMethodDecl>(funcDecl)->isMoveAssignmentOperator())) {
+ // Implicit copy-assignment gets the same special treatment as implicit
+ // copy-constructors.
+ emitImplicitAssignmentOperatorBody(args);
+ } else if (body) {
if (mlir::failed(emitFunctionBody(body))) {
fn.erase();
return nullptr;