Fixed enum constant evaluation assertions.

llvm-svn: 134139
This commit is contained in:
Abramo Bagnara 2011-06-30 09:36:05 +00:00
parent 1406d6c037
commit 2caedf449e
1 changed files with 13 additions and 6 deletions

View File

@ -955,17 +955,21 @@ public:
IntExprEvaluator(EvalInfo &info, APValue &result) IntExprEvaluator(EvalInfo &info, APValue &result)
: ExprEvaluatorBaseTy(info), Result(result) {} : ExprEvaluatorBaseTy(info), Result(result) {}
bool Success(const llvm::APSInt &SI, const Expr *E) { bool Success(const llvm::APSInt &SI, QualType Ty) {
assert(E->getType()->isIntegralOrEnumerationType() && assert(Ty->isIntegralOrEnumerationType() &&
"Invalid evaluation result."); "Invalid evaluation result.");
assert(SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() && assert(SI.isSigned() == Ty->isSignedIntegerOrEnumerationType() &&
"Invalid evaluation result."); "Invalid evaluation result.");
assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && assert(SI.getBitWidth() == Info.Ctx.getIntWidth(Ty) &&
"Invalid evaluation result."); "Invalid evaluation result.");
Result = APValue(SI); Result = APValue(SI);
return true; 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) { bool Success(const llvm::APInt &I, const Expr *E) {
assert(E->getType()->isIntegralOrEnumerationType() && assert(E->getType()->isIntegralOrEnumerationType() &&
"Invalid evaluation result."); "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) { bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
// Enums are integer constant exprs. // Enums are integer constant exprs.
if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) {
return Success(ECD->getInitVal(), E); // 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++, const, non-volatile integers initialized with ICEs are ICEs.
// In C, they can also be folded, although they are not ICEs. // In C, they can also be folded, although they are not ICEs.