]> granicus.if.org Git - clang/commitdiff
When reference binding array rvalues, such as those created by compound
authorPeter Collingbourne <peter@pcc.me.uk>
Sun, 13 Nov 2011 00:51:30 +0000 (00:51 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Sun, 13 Nov 2011 00:51:30 +0000 (00:51 +0000)
literals of array type, materialise a temporary.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144483 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/CodeGenCXX/compound-literals.cpp

index a24e708b1e76b2f954fb4d8360e0f10809f9c23e..c24f8aa5e21345cb78cf624c3b3b966d85806ba8 100644 (file)
@@ -3187,7 +3187,7 @@ static void TryReferenceInitialization(Sema &S,
     if (T1Quals != T2Quals)
       Sequence.AddQualificationConversionStep(cv1T1, ValueKind);
     Sequence.AddReferenceBindingStep(cv1T1,
-         /*bindingTemporary=*/(InitCategory.isPRValue() && !T2->isArrayType()));
+                                 /*bindingTemporary=*/InitCategory.isPRValue());
     return;
   }
 
index cd44e97c6744fce6098cd1ab3fdce2f3071191f2..f520ff99516556f9e69a595b9ca02b08c8fa96be 100644 (file)
@@ -25,3 +25,15 @@ int f() {
   // CHECK-NEXT: ret i32 [[RESULT]]
   return ((Y){17, "seventeen"}).i;
 }
+
+// CHECK: define i32 @_Z1gv()
+int g() {
+  // CHECK: store [2 x i32]* %{{[a-z0-9.]+}}, [2 x i32]** [[V:%[a-z0-9.]+]]
+  const int (&v)[2] = (int [2]) {1,2};
+
+  // CHECK: [[A:%[a-z0-9.]+]] = load [2 x i32]** [[V]]
+  // CHECK-NEXT: [[A0ADDR:%[a-z0-9.]+]] = getelementptr inbounds [2 x i32]* [[A]], i32 0, {{.*}} 0
+  // CHECK-NEXT: [[A0:%[a-z0-9.]+]] = load i32* [[A0ADDR]]
+  // CHECK-NEXT: ret i32 [[A0]]
+  return v[0];
+}