From f3e67de85aed2c3582755845d39474948c0cc63a Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 9 Apr 2015 22:50:07 +0000 Subject: [CodeGen] Do a more principled fix for PR231653, always use the inner type. We were still using the MaterializeTemporaryExpr's type to check if the transform is legal. Always use the inner Expr type. llvm-svn: 234543 --- clang/lib/CodeGen/CGExpr.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'clang/lib/CodeGen/CGExpr.cpp') diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dd66f6cc7a1..4147317963b 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -300,27 +300,26 @@ createReferenceTemporary(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *Inner) { switch (M->getStorageDuration()) { case SD_FullExpression: - case SD_Automatic: + case SD_Automatic: { // If we have a constant temporary array or record try to promote it into a // constant global under the same rules a normal constant would've been // promoted. This is easier on the optimizer and generally emits fewer // instructions. + QualType Ty = Inner->getType(); if (CGF.CGM.getCodeGenOpts().MergeAllConstants && - (M->getType()->isArrayType() || M->getType()->isRecordType()) && - CGF.CGM.isTypeConstant(M->getType(), true)) - if (llvm::Constant *Init = - CGF.CGM.EmitConstantExpr(Inner, Inner->getType(), &CGF)) { + (Ty->isArrayType() || Ty->isRecordType()) && + CGF.CGM.isTypeConstant(Ty, true)) + if (llvm::Constant *Init = CGF.CGM.EmitConstantExpr(Inner, Ty, &CGF)) { auto *GV = new llvm::GlobalVariable( CGF.CGM.getModule(), Init->getType(), /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, Init, ".ref.tmp"); - GV->setAlignment(CGF.getContext() - .getTypeAlignInChars(Inner->getType()) - .getQuantity()); + GV->setAlignment( + CGF.getContext().getTypeAlignInChars(Ty).getQuantity()); // FIXME: Should we put the new global into a COMDAT? return GV; } - return CGF.CreateMemTemp(Inner->getType(), "ref.tmp"); - + return CGF.CreateMemTemp(Ty, "ref.tmp"); + } case SD_Thread: case SD_Static: return CGF.CGM.GetAddrOfGlobalTemporary(M, Inner); -- cgit v1.2.3