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) {


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to