diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2015-03-17 02:21:31 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2015-03-17 02:21:31 +0000 |
commit | cf191adaf5647f32d62cee7eda8e1775666ddba2 (patch) | |
tree | 2d26cc7a4863a4675155b9b4fbd308be7d7d9a3e | |
parent | d9c4c2487f42265f6c64102d99c006903f7499b8 (diff) | |
download | bcm5719-llvm-cf191adaf5647f32d62cee7eda8e1775666ddba2.tar.gz bcm5719-llvm-cf191adaf5647f32d62cee7eda8e1775666ddba2.zip |
Fix the LLVM type used when lowering initializer list reference temporaries to global variables.
llvm-svn: 232454
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 7 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp | 24 |
2 files changed, 29 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 35275e58e93..92098752cb9 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -316,13 +316,16 @@ createReferenceTemporary(CodeGenFunction &CGF, GV->setAlignment( CGF.getContext().getTypeAlignInChars(M->getType()).getQuantity()); // FIXME: Should we put the new global into a COMDAT? - return GV; + return llvm::ConstantExpr::getBitCast( + GV, CGF.ConvertTypeForMem(Inner->getType())->getPointerTo()); } return CGF.CreateMemTemp(Inner->getType(), "ref.tmp"); case SD_Thread: case SD_Static: - return CGF.CGM.GetAddrOfGlobalTemporary(M, Inner); + return llvm::ConstantExpr::getBitCast( + CGF.CGM.GetAddrOfGlobalTemporary(M, Inner), + CGF.ConvertTypeForMem(Inner->getType())->getPointerTo()); case SD_Dynamic: llvm_unreachable("temporary can't have dynamic storage duration"); diff --git a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp index 382694ec03f..b187aed881f 100644 --- a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -482,3 +482,27 @@ namespace ConstExpr { f({C(1), C(2), C(3)}); } } + +namespace B19773010 { + template <class T1, class T2> struct pair { + T1 first; + T2 second; + constexpr pair(T1 a, T2 b) : first(a), second(b) {} + }; + + enum E { ENUM_CONSTANT }; + struct testcase { + testcase(std::initializer_list<pair<const char *, E>>); + }; + void f1() { + // CHECK-LABEL: @_ZN9B197730102f1Ev + testcase a{{"", ENUM_CONSTANT}}; + // CHECK: store %"struct.B19773010::pair"* getelementptr inbounds ([1 x %"struct.B19773010::pair"], [1 x %"struct.B19773010::pair"]* bitcast ([1 x { i8*, i32 }]* @.ref.tmp{{.*}} to [1 x %"struct.B19773010::pair"]*), i64 0, i64 0), %"struct.B19773010::pair"** %__begin_, align 8 + } + void f2() { + // CHECK-LABEL: @_ZN9B197730102f2Ev + // CHECK: store %"struct.B19773010::pair"* getelementptr inbounds ([1 x %"struct.B19773010::pair"], [1 x %"struct.B19773010::pair"]* bitcast ([1 x { i8*, i32 }]* @_ZGRZN9B197730102f2EvE1p_ to [1 x %"struct.B19773010::pair"]*), i64 0, i64 0), %"struct.B19773010::pair"** getelementptr inbounds ([2 x %"class.std::initializer_list.10"], [2 x %"class.std::initializer_list.10"]* @_ZZN9B197730102f2EvE1p, i64 0, i64 1, i32 0), align 8 + static std::initializer_list<pair<const char *, E>> a, p[2] = + {a, {{"", ENUM_CONSTANT}}}; + } +} |