diff options
author | Abramo Bagnara <abramo.bagnara@gmail.com> | 2011-06-30 09:36:05 +0000 |
---|---|---|
committer | Abramo Bagnara <abramo.bagnara@gmail.com> | 2011-06-30 09:36:05 +0000 |
commit | bfbdcd861a4364bfc21a9e5047bdbd56812d6693 (patch) | |
tree | fbf5ab53d93e3af608363e7cea5f43c464c0362c /lib/AST/ExprConstant.cpp | |
parent | ca0d0d4a0d6ecd256d4bf8c1a0dc183a83119833 (diff) |
Fixed enum constant evaluation assertions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134139 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 7d2ea13d0a..1be23fc990 100644 --- a/lib/AST/ExprConstant.cpp +++ b/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<EnumConstantDecl>(D)) - return Success(ECD->getInitVal(), E); + if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(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. |