[llvm-branch-commits] [cfe-branch] r303167 - Merging r302817:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue May 16 06:33:49 PDT 2017


Author: tstellar
Date: Tue May 16 08:33:48 2017
New Revision: 303167

URL: http://llvm.org/viewvc/llvm-project?rev=303167&view=rev
Log:
Merging r302817:

------------------------------------------------------------------------
r302817 | rsmith | 2017-05-11 14:58:24 -0400 (Thu, 11 May 2017) | 9 lines

PR22877: When constructing an array via a constructor with a default argument
in list-initialization, run cleanups for the default argument after each
iteration of the initialization loop.

We previously only ran the destructor for any temporary once, at the end of the
complete loop, rather than once per iteration!

Re-commit of r302750, reverted in r302776.

------------------------------------------------------------------------

Added:
    cfe/branches/release_40/test/CodeGenCXX/array-default-argument.cpp
Modified:
    cfe/branches/release_40/lib/CodeGen/CGExprAgg.cpp

Modified: cfe/branches/release_40/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/lib/CodeGen/CGExprAgg.cpp?rev=303167&r1=303166&r2=303167&view=diff
==============================================================================
--- cfe/branches/release_40/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/branches/release_40/lib/CodeGen/CGExprAgg.cpp Tue May 16 08:33:48 2017
@@ -505,12 +505,20 @@ void AggExprEmitter::EmitArrayInit(Addre
     currentElement->addIncoming(element, entryBB);
 
     // Emit the actual filler expression.
-    LValue elementLV =
-      CGF.MakeAddrLValue(Address(currentElement, elementAlign), elementType);
-    if (filler)
-      EmitInitializationToLValue(filler, elementLV);
-    else
-      EmitNullInitializationToLValue(elementLV);
+    {
+      // C++1z [class.temporary]p5:
+      //   when a default constructor is called to initialize an element of
+      //   an array with no corresponding initializer [...] the destruction of
+      //   every temporary created in a default argument is sequenced before
+      //   the construction of the next array element, if any
+      CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
+      LValue elementLV =
+        CGF.MakeAddrLValue(Address(currentElement, elementAlign), elementType);
+      if (filler)
+        EmitInitializationToLValue(filler, elementLV);
+      else
+        EmitNullInitializationToLValue(elementLV);
+    }
 
     // Move on to the next element.
     llvm::Value *nextElement =

Added: cfe/branches/release_40/test/CodeGenCXX/array-default-argument.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/test/CodeGenCXX/array-default-argument.cpp?rev=303167&view=auto
==============================================================================
--- cfe/branches/release_40/test/CodeGenCXX/array-default-argument.cpp (added)
+++ cfe/branches/release_40/test/CodeGenCXX/array-default-argument.cpp Tue May 16 08:33:48 2017
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s -triple %itanium_abi_triple | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-EH
+
+struct A {
+  A();
+  ~A();
+};
+
+struct B {
+  B(A = A());
+  ~B();
+};
+
+void f();
+// CHECK-LABEL: define void @_Z1gv()
+void g() {
+  // CHECK: br label %[[LOOP:.*]]
+
+  // [[LOOP]]:
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1AC1Ev([[TEMPORARY:.*]])
+  // CHECK-EH:  unwind label %[[PARTIAL_ARRAY_LPAD:.*]]
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1BC1E1A({{.*}}, [[TEMPORARY]])
+  // CHECK-EH:  unwind label %[[A_AND_PARTIAL_ARRAY_LPAD:.*]]
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1AD1Ev([[TEMPORARY]])
+  // CHECK-EH:  unwind label %[[PARTIAL_ARRAY_LPAD]]
+  // CHECK: getelementptr {{.*}}, i{{[0-9]*}} 1
+  // CHECK: icmp eq
+  // CHECK: br i1 {{.*}} label %[[LOOP]]
+  B b[5];
+
+  // CHECK: {{call|invoke}} void @_Z1fv()
+  f();
+
+  // CHECK-NOT: @_ZN1AD1Ev(
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1BD1Ev(
+}




More information about the llvm-branch-commits mailing list