diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2011-11-13 00:51:30 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2011-11-13 00:51:30 +0000 |
commit | 65bfd682010f599a9a04fc7523e95e28c27508ba (patch) | |
tree | 0a97579e6cb7851985295c450d54a1ddbcd1c170 | |
parent | 1bf9a9e6a5bdc0de7939908855dcddf46b661800 (diff) |
When reference binding array rvalues, such as those created by compound
literals of array type, materialise a temporary.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144483 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaInit.cpp | 2 | ||||
-rw-r--r-- | test/CodeGenCXX/compound-literals.cpp | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index a24e708b1e..c24f8aa5e2 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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; } diff --git a/test/CodeGenCXX/compound-literals.cpp b/test/CodeGenCXX/compound-literals.cpp index cd44e97c67..f520ff9951 100644 --- a/test/CodeGenCXX/compound-literals.cpp +++ b/test/CodeGenCXX/compound-literals.cpp @@ -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]; +} |