diff options
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 13 | ||||
-rw-r--r-- | test/CodeGenCXX/const-init-cxx11.cpp | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index d5ef402d22..8ed36aac5f 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -214,6 +214,14 @@ public: // l-values. Value *VisitDeclRefExpr(DeclRefExpr *E) { + VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()); + if (!VD && !isa<EnumConstantDecl>(E->getDecl())) + return EmitLoadOfLValue(E); + if (VD && !VD->isUsableInConstantExpressions()) + return EmitLoadOfLValue(E); + + // This is an enumerator or a variable which is usable in constant + // expressions. Try to emit its value instead. Expr::EvalResult Result; bool IsReferenceConstant = false; QualType EvalTy = E->getType(); @@ -232,10 +240,11 @@ public: llvm::Constant *C = CGF.CGM.EmitConstantValue(Result.Val, EvalTy, &CGF); // Make sure we emit a debug reference to the global variable. - if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { + if (VD) { if (!CGF.getContext().DeclMustBeEmitted(VD)) CGF.EmitDeclRefExprDbgValue(E, C); - } else if (isa<EnumConstantDecl>(E->getDecl())) { + } else { + assert(isa<EnumConstantDecl>(E->getDecl())); CGF.EmitDeclRefExprDbgValue(E, C); } diff --git a/test/CodeGenCXX/const-init-cxx11.cpp b/test/CodeGenCXX/const-init-cxx11.cpp index a1486c1175..8d92b81feb 100644 --- a/test/CodeGenCXX/const-init-cxx11.cpp +++ b/test/CodeGenCXX/const-init-cxx11.cpp @@ -370,7 +370,7 @@ namespace InitFromConst { const bool b = true; const int n = 5; - const double d = 4.3; + constexpr double d = 4.3; struct S { int n = 7; S *p = 0; }; constexpr S s = S(); |