From b2b81439a39136ea5eda1a80f784efbbd61cc384 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 9 Apr 2015 16:09:29 +0000 Subject: [CodeGen] When promoting a reference temporary to a global use the inner type to fold it. The MaterializeTemporaryExpr can have a different type than the inner expression, miscompiling the constant. PR23165. llvm-svn: 234499 --- clang/lib/CodeGen/CGExpr.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index f86e970c25a..dd66f6cc7a1 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -309,12 +309,13 @@ createReferenceTemporary(CodeGenFunction &CGF, (M->getType()->isArrayType() || M->getType()->isRecordType()) && CGF.CGM.isTypeConstant(M->getType(), true)) if (llvm::Constant *Init = - CGF.CGM.EmitConstantExpr(Inner, M->getType(), &CGF)) { + CGF.CGM.EmitConstantExpr(Inner, Inner->getType(), &CGF)) { auto *GV = new llvm::GlobalVariable( CGF.CGM.getModule(), Init->getType(), /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, Init, ".ref.tmp"); - GV->setAlignment( - CGF.getContext().getTypeAlignInChars(M->getType()).getQuantity()); + GV->setAlignment(CGF.getContext() + .getTypeAlignInChars(Inner->getType()) + .getQuantity()); // FIXME: Should we put the new global into a COMDAT? return GV; } -- cgit v1.2.3