From: Nick Lewycky Date: Wed, 18 Mar 2015 01:06:24 +0000 (+0000) Subject: Fix the LLVM type used when lowering initializer list reference temporaries to global... X-Git-Tag: llvmorg-3.7.0-rc1~8932 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84146bee6c3fc481926e25ed2936aa0bf4a0bfde;p=platform%2Fupstream%2Fllvm.git Fix the LLVM type used when lowering initializer list reference temporaries to global variables. Reapplies r232454 with fix for PR22940. llvm-svn: 232579 --- diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 35275e5..5ba51cc 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -341,14 +341,15 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) { M->getType().getObjCLifetime() != Qualifiers::OCL_None && M->getType().getObjCLifetime() != Qualifiers::OCL_ExplicitNone) { llvm::Value *Object = createReferenceTemporary(*this, M, E); - LValue RefTempDst = MakeAddrLValue(Object, M->getType()); - if (auto *Var = dyn_cast(Object)) { + Object = llvm::ConstantExpr::getBitCast( + Var, ConvertTypeForMem(E->getType())->getPointerTo()); // We should not have emitted the initializer for this temporary as a // constant. assert(!Var->hasInitializer()); Var->setInitializer(CGM.EmitNullConstant(E->getType())); } + LValue RefTempDst = MakeAddrLValue(Object, M->getType()); switch (getEvaluationKind(E->getType())) { default: llvm_unreachable("expected scalar or aggregate expression"); @@ -387,6 +388,8 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) { // Create and initialize the reference temporary. llvm::Value *Object = createReferenceTemporary(*this, M, E); if (auto *Var = dyn_cast(Object)) { + Object = llvm::ConstantExpr::getBitCast( + Var, ConvertTypeForMem(E->getType())->getPointerTo()); // If the temporary is a global and has a constant initializer or is a // constant temporary that we promoted to a global, we may have already // initialized it. diff --git a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp index 382694e..43afaef 100644 --- a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -482,3 +482,36 @@ namespace ConstExpr { f({C(1), C(2), C(3)}); } } + +namespace B19773010 { + template struct pair { + T1 first; + T2 second; + constexpr pair() : first(), second() {} + constexpr pair(T1 a, T2 b) : first(a), second(b) {} + }; + + enum E { ENUM_CONSTANT }; + struct testcase { + testcase(std::initializer_list>); + }; + 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> a, p[2] = + {a, {{"", ENUM_CONSTANT}}}; + } + + void PR22940_helper(const pair&) { } + void PR22940() { + // CHECK-LABEL: @_ZN9B197730107PR22940Ev + // CHECK-NOT: call {{.*}} @_ZN9B197730104pairIPviEC{{.}}Ev( + // CHECK: call {{.*}} @_ZN9B1977301014PR22940_helperERKNS_4pairIPviEE( + PR22940_helper(pair()); + } +}