Skip to content

Commit fcc764d

Browse files
committed
When reference binding array rvalues, such as those created by compound
literals of array type, materialise a temporary. llvm-svn: 144483
1 parent 38b3f31 commit fcc764d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3187,7 +3187,7 @@ static void TryReferenceInitialization(Sema &S,
31873187
if (T1Quals != T2Quals)
31883188
Sequence.AddQualificationConversionStep(cv1T1, ValueKind);
31893189
Sequence.AddReferenceBindingStep(cv1T1,
3190-
/*bindingTemporary=*/(InitCategory.isPRValue() && !T2->isArrayType()));
3190+
/*bindingTemporary=*/InitCategory.isPRValue());
31913191
return;
31923192
}
31933193

clang/test/CodeGenCXX/compound-literals.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ int f() {
2525
// CHECK-NEXT: ret i32 [[RESULT]]
2626
return ((Y){17, "seventeen"}).i;
2727
}
28+
29+
// CHECK: define i32 @_Z1gv()
30+
int g() {
31+
// CHECK: store [2 x i32]* %{{[a-z0-9.]+}}, [2 x i32]** [[V:%[a-z0-9.]+]]
32+
const int (&v)[2] = (int [2]) {1,2};
33+
34+
// CHECK: [[A:%[a-z0-9.]+]] = load [2 x i32]** [[V]]
35+
// CHECK-NEXT: [[A0ADDR:%[a-z0-9.]+]] = getelementptr inbounds [2 x i32]* [[A]], i32 0, {{.*}} 0
36+
// CHECK-NEXT: [[A0:%[a-z0-9.]+]] = load i32* [[A0ADDR]]
37+
// CHECK-NEXT: ret i32 [[A0]]
38+
return v[0];
39+
}

0 commit comments

Comments
 (0)