bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
SourceLocation *Loc = 0,
bool isEvaluated = true) const;
+ bool isIntegerConstantExprInternal(llvm::APSInt &Result, ASTContext &Ctx,
+ SourceLocation *Loc = 0,
+ bool isEvaluated = true) const;
bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
llvm::APSInt X;
return isIntegerConstantExpr(X, Ctx, Loc);
/// EvalResult is a struct with detailed info about an evaluated expression.
struct EvalResult {
- /// Val - This is the scalar value the expression can be folded to.
+ /// Val - This is the value the expression can be folded to.
APValue Val;
/// HasSideEffects - Whether the evaluated expression has side effects.
/// cast+dereference.
bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
SourceLocation *Loc, bool isEvaluated) const {
+ if (!isIntegerConstantExprInternal(Result, Ctx, Loc, isEvaluated))
+ return false;
+ assert(Result == EvaluateAsInt(Ctx) && "Inconsistent Evaluate() result!");
+ return true;
+}
+
+bool Expr::isIntegerConstantExprInternal(llvm::APSInt &Result, ASTContext &Ctx,
+ SourceLocation *Loc, bool isEvaluated) const {
+
// Pretest for integral type; some parts of the code crash for types that
// can't be sized.
if (!getType()->isIntegralType()) {
return cast<ParenExpr>(this)->getSubExpr()->
isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
case IntegerLiteralClass:
+ // NOTE: getValue() returns an APInt, we must set sign.
Result = cast<IntegerLiteral>(this)->getValue();
Result.setIsUnsigned(getType()->isUnsignedIntegerType());
break;
// The result of the constant expr is the RHS.
Result = RHS;
- return true;
+ break;
}
assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!");
}
// Evaluate the false one first, discard the result.
- if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
+ llvm::APSInt Tmp;
+ if (FalseExp && !FalseExp->isIntegerConstantExpr(Tmp, Ctx, Loc, false))
return false;
- // Evalute the true one, capture the result.
+ // Evalute the true one, capture the result. Note that if TrueExp
+ // is False then this is an instant of the gcc missing LHS
+ // extension, and we will just reuse Result.
if (TrueExp &&
!TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
return false;