[cfe-commits] r134320 - /cfe/trunk/lib/AST/ExprConstant.cpp
Abramo Bagnara
abramo.bagnara at gmail.com
Sat Jul 2 06:13:53 PDT 2011
Author: abramo
Date: Sat Jul 2 08:13:53 2011
New Revision: 134320
URL: http://llvm.org/viewvc/llvm-project?rev=134320&view=rev
Log:
Rewritten fix in r134139 to conform evaluation result to original evaluation context.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=134320&r1=134319&r2=134320&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Jul 2 08:13:53 2011
@@ -955,21 +955,17 @@
IntExprEvaluator(EvalInfo &info, APValue &result)
: ExprEvaluatorBaseTy(info), Result(result) {}
- bool Success(const llvm::APSInt &SI, QualType Ty) {
- assert(Ty->isIntegralOrEnumerationType() &&
+ bool Success(const llvm::APSInt &SI, const Expr *E) {
+ assert(E->getType()->isIntegralOrEnumerationType() &&
"Invalid evaluation result.");
- assert(SI.isSigned() == Ty->isSignedIntegerOrEnumerationType() &&
+ assert(SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() &&
"Invalid evaluation result.");
- assert(SI.getBitWidth() == Info.Ctx.getIntWidth(Ty) &&
+ assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) &&
"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.");
@@ -1111,9 +1107,23 @@
bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
// Enums are integer constant exprs.
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());
+ // Check for signedness/width mismatches between E type and ECD value.
+ bool SameSign = (ECD->getInitVal().isSigned()
+ == E->getType()->isSignedIntegerOrEnumerationType());
+ bool SameWidth = (ECD->getInitVal().getBitWidth()
+ == Info.Ctx.getIntWidth(E->getType()));
+ if (SameSign && SameWidth)
+ return Success(ECD->getInitVal(), E);
+ else {
+ // Get rid of mismatch (otherwise Success assertions will fail)
+ // by computing a new value matching the type of E.
+ llvm::APSInt Val = ECD->getInitVal();
+ if (!SameSign)
+ Val.setIsSigned(!ECD->getInitVal().isSigned());
+ if (!SameWidth)
+ Val = Val.extOrTrunc(Info.Ctx.getIntWidth(E->getType()));
+ return Success(Val, E);
+ }
}
// In C++, const, non-volatile integers initialized with ICEs are ICEs.
More information about the cfe-commits
mailing list