[cfe-commits] r103872 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGenCXX/nrvo.cpp

Douglas Gregor dgregor at apple.com
Sat May 15 09:39:56 PDT 2010


Author: dgregor
Date: Sat May 15 11:39:56 2010
New Revision: 103872

URL: http://llvm.org/viewvc/llvm-project?rev=103872&view=rev
Log:
When applying the named return value optimization, we still need to
destroy the variable along the exceptional edge; it's only during
normal execution that we avoid destroying this variable.

Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/test/CodeGenCXX/nrvo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=103872&r1=103871&r2=103872&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat May 15 11:39:56 2010
@@ -659,7 +659,7 @@
     DtorTy = getContext().getBaseElementType(Array);
   if (const RecordType *RT = DtorTy->getAs<RecordType>())
     if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {      
-      if (!ClassDecl->hasTrivialDestructor() && !NRVO) {
+      if (!ClassDecl->hasTrivialDestructor()) {
         // Note: We suppress the destructor call when this is an NRVO variable.
         llvm::Value *Loc = DeclPtr;
         if (isByRef)
@@ -693,7 +693,9 @@
             EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
           }
         } else {
-          {
+          if (!NRVO) {
+            // We don't call the destructor along the normal edge if we're
+            // applying the NRVO.
             DelayedCleanupBlock Scope(*this);
             EmitCXXDestructorCall(D, Dtor_Complete, /*ForVirtualBase=*/false,
                                   Loc);
@@ -701,6 +703,7 @@
             // Make sure to jump to the exit block.
             EmitBranch(Scope.getCleanupExitBlock());
           }
+          
           if (Exceptions) {
             EHCleanupBlock Cleanup(*this);
             EmitCXXDestructorCall(D, Dtor_Complete, /*ForVirtualBase=*/false,

Modified: cfe/trunk/test/CodeGenCXX/nrvo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/nrvo.cpp?rev=103872&r1=103871&r2=103872&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/nrvo.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/nrvo.cpp Sat May 15 11:39:56 2010
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -fexceptions -o - %s | FileCheck --check-prefix=CHECK-EH %s
 
 // Test code generation for the named return value optimization.
 class X {
@@ -9,11 +10,15 @@
 };
 
 // CHECK: define void @_Z5test0v
+// CHECK-EH: define void @_Z5test0v
 X test0() {
   X x;
   // CHECK-NOT: call void @_ZN1XD1Ev
   // CHECK: ret void
+  // CHECK-EH: ret void
   return x;
+  // CHECK-EH: ehcleanup:
+  // CHECK-EH: invoke void @_ZN1XD1Ev
 }
 
 // CHECK: define void @_Z5test1b(
@@ -25,9 +30,12 @@
   if (B)
     return (x);
   return x;
+  // CHECK-EH: ehcleanup:
+  // CHECK-EH: invoke void @_ZN1XD1Ev
 }
 
 // CHECK: define void @_Z5test2b
+// CHECK-EH: define void @_Z5test2b
 X test2(bool B) {
   // No NRVO
   // CHECK: call void @_ZN1XC1Ev
@@ -35,13 +43,18 @@
   // CHECK: call void @_ZN1XC1Ev
   X y;
   // CHECK: call void @_ZN1XC1ERKS_
+  // CHECK-EH: invoke void @_ZN1XC1ERKS_
   if (B)
     return y;
   // CHECK: call void @_ZN1XC1ERKS_
+  // CHECK-EH: invoke void @_ZN1XC1ERKS_
   return x;
   // CHECK: call void @_ZN1XD1Ev
   // CHECK: call void @_ZN1XD1Ev
   // CHECK: ret void
+  // CHECK-EH: ehcleanup:
+  // CHECK-EH: invoke void @_ZN1XD1Ev
+  // CHECK-EH: invoke void @_ZN1XD1Ev
 }
 
 X test3(bool B) {





More information about the cfe-commits mailing list