[clang] fbd7360 - [clang][Interp] Short-cirtuit Move/Copy constructors if we can
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 5 02:29:48 PDT 2024
Author: Timm Bäder
Date: 2024-07-05T11:29:32+02:00
New Revision: fbd736062e043d34cddd6031b4ee93954d4bf199
URL: https://github.com/llvm/llvm-project/commit/fbd736062e043d34cddd6031b4ee93954d4bf199
DIFF: https://github.com/llvm/llvm-project/commit/fbd736062e043d34cddd6031b4ee93954d4bf199.diff
LOG: [clang][Interp] Short-cirtuit Move/Copy constructors if we can
Added:
Modified:
clang/lib/AST/Interp/Compiler.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp
index 775cabf7f8c59..2fd20d8022126 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -2447,6 +2447,12 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
if (T->isRecordType()) {
const CXXConstructorDecl *Ctor = E->getConstructor();
+ // Trivial copy/move constructor. Avoid copy.
+ if (Ctor->isDefaulted() && Ctor->isCopyOrMoveConstructor() &&
+ E->getArg(0)->isTemporaryObject(Ctx.getASTContext(),
+ T->getAsCXXRecordDecl()))
+ return this->visitInitializer(E->getArg(0));
+
// If we're discarding a construct expression, we still need
// to allocate a variable and call the constructor and destructor.
if (DiscardResult) {
More information about the cfe-commits
mailing list