From ef94a4b2c4a620d1b712c4c07ee220024b0dc3cf Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Tue, 27 May 2014 16:46:27 +0000 Subject: [PATCH] Revert small change to EmitDeclRefLValue That small change, although it looked harmless, it made emitting the LValue on the PHI node without the proper cast. Reverting it fixes PR19841. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209663 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExpr.cpp | 17 ++++++++--------- test/CodeGen/pr19841.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 test/CodeGen/pr19841.cpp diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index ba0e468c23..966edc46f2 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1798,16 +1798,15 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { const NamedDecl *ND = E->getDecl(); CharUnits Alignment = getContext().getDeclAlign(ND); QualType T = E->getType(); - const auto *VD = dyn_cast(ND); - // Global Named registers access via intrinsics only - if (VD && VD->getStorageClass() == SC_Register && - VD->hasAttr() && !VD->isLocalVarDecl()) - return EmitGlobalNamedRegister(VD, CGM, Alignment); + if (const auto *VD = dyn_cast(ND)) { + // Global Named registers access via intrinsics only + if (VD->getStorageClass() == SC_Register && + VD->hasAttr() && !VD->isLocalVarDecl()) + return EmitGlobalNamedRegister(VD, CGM, Alignment); - // A DeclRefExpr for a reference initialized by a constant expression can - // appear without being odr-used. Directly emit the constant initializer. - if (VD) { + // A DeclRefExpr for a reference initialized by a constant expression can + // appear without being odr-used. Directly emit the constant initializer. const Expr *Init = VD->getAnyInitializer(VD); if (Init && !isa(VD) && VD->getType()->isReferenceType() && VD->isUsableInConstantExpressions(getContext()) && @@ -1833,7 +1832,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { return MakeAddrLValue(Aliasee, T, Alignment); } - if (VD) { + if (const auto *VD = dyn_cast(ND)) { // Check if this is a global variable. if (VD->hasLinkage() || VD->isStaticDataMember()) return EmitGlobalVarDeclLValue(*this, E, VD); diff --git a/test/CodeGen/pr19841.cpp b/test/CodeGen/pr19841.cpp new file mode 100644 index 0000000000..4350625d18 --- /dev/null +++ b/test/CodeGen/pr19841.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +namespace Common { +enum RenderMode { + kRenderEGA, + kRenderCGA +}; +class C; +class A { + A(); + C *_vm; + unsigned char _highlightColorTableVGA[]; + static const unsigned char b[]; +}; +class B { +public: + Common::RenderMode _configRenderMode; +}; +class C : public B {}; +A::A() { + 0 == Common::kRenderCGA || _vm->_configRenderMode == Common::kRenderEGA + ? b + : _highlightColorTableVGA; +// Make sure the PHI value is casted correctly to the PHI type +// CHECK: %cond-lvalue = phi [0 x i8]* [ bitcast ([1 x i8]* @_ZN6Common1A1bE to [0 x i8]*), %cond.true ], [ %_highlightColorTableVGA, %cond.false ] +} +const unsigned char A::b[] = { 0 }; +} -- 2.40.0