From 2caedf449e640d14919402c7da27a36436971b95 Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Thu, 30 Jun 2011 09:36:05 +0000 Subject: Fixed enum constant evaluation assertions. llvm-svn: 134139 --- clang/lib/AST/ExprConstant.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'clang/lib/AST/ExprConstant.cpp') diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7d2ea13d0a7..1be23fc9903 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -955,17 +955,21 @@ public: IntExprEvaluator(EvalInfo &info, APValue &result) : ExprEvaluatorBaseTy(info), Result(result) {} - bool Success(const llvm::APSInt &SI, const Expr *E) { - assert(E->getType()->isIntegralOrEnumerationType() && + bool Success(const llvm::APSInt &SI, QualType Ty) { + assert(Ty->isIntegralOrEnumerationType() && "Invalid evaluation result."); - assert(SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() && + assert(SI.isSigned() == Ty->isSignedIntegerOrEnumerationType() && "Invalid evaluation result."); - assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && + assert(SI.getBitWidth() == Info.Ctx.getIntWidth(Ty) && "Invalid evaluation result."); Result = APValue(SI); return true; } + bool Success(const llvm::APSInt &SI, const Expr *E) { + return Success(SI, E->getType()); + } + bool Success(const llvm::APInt &I, const Expr *E) { assert(E->getType()->isIntegralOrEnumerationType() && "Invalid evaluation result."); @@ -1106,8 +1110,11 @@ static bool EvaluateInteger(const Expr* E, APSInt &Result, EvalInfo &Info) { bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) { // Enums are integer constant exprs. - if (const EnumConstantDecl *ECD = dyn_cast(D)) - return Success(ECD->getInitVal(), E); + if (const EnumConstantDecl *ECD = dyn_cast(D)) { + // Note: provide the type of ECD (rather than that of E), + // so that signedness/width will match the ECD init value. + return Success(ECD->getInitVal(), ECD->getType()); + } // In C++, const, non-volatile integers initialized with ICEs are ICEs. // In C, they can also be folded, although they are not ICEs. -- cgit v1.2.3