diff options
author | Anders Carlsson <andersca@mac.com> | 2008-11-24 04:21:33 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-11-24 04:21:33 +0000 |
commit | 4c76e935074a2aef01e3560f5acc3c55d4f017ae (patch) | |
tree | 0fe2228cef5c34b56c4053c4b1483c8613955b6a /clang/lib/AST | |
parent | 1cbaacc4a0f05f4c6c54417ca3090aa3974b095a (diff) | |
download | bcm5719-llvm-4c76e935074a2aef01e3560f5acc3c55d4f017ae.tar.gz bcm5719-llvm-4c76e935074a2aef01e3560f5acc3c55d4f017ae.zip |
Fix bug in the constant evaluator. Fixes PR3115.
llvm-svn: 59938
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 6fba884028d..7b927f46288 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -505,14 +505,12 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) { Result = EvaluateBuiltinClassifyType(E); return true; - case Builtin::BI__builtin_constant_p: { + case Builtin::BI__builtin_constant_p: // __builtin_constant_p always has one operand: it returns true if that // operand can be folded, false otherwise. - APValue Res; - Result = E->getArg(0)->Evaluate(Res, Info.Ctx); + Result = E->getArg(0)->isEvaluatable(Info.Ctx); return true; } - } } bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { @@ -537,43 +535,45 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { // These need to be handled specially because the operands aren't // necessarily integral bool bres; - bool isEvaluated = true; if (HandleConversionToBool(E->getLHS(), bres, Info)) { // We were able to evaluate the LHS, see if we can get away with not // evaluating the RHS: 0 && X -> 0, 1 || X -> 1 - } else { - // We can't evaluate the LHS; however, sometimes the result - // is determined by the RHS: X && 0 -> 0, X || 1 -> 1. - if (!HandleConversionToBool(E->getRHS(), bres, Info)) { - // We can't evaluate. - return false; + if (bres == (E->getOpcode() == BinaryOperator::LOr) || + !bres == (E->getOpcode() == BinaryOperator::LAnd)) { + Result.zextOrTrunc(getIntTypeSizeInBits(E->getType())); + Result.setIsUnsigned(E->getType()->isUnsignedIntegerType()); + Result = bres; + + return true; } - - // We did not evaluate the LHS - isEvaluated = false; - } - if (bres == (E->getOpcode() == BinaryOperator::LOr) || - !bres == (E->getOpcode() == BinaryOperator::LAnd)) { - Result.zextOrTrunc(getIntTypeSizeInBits(E->getType())); - Result.setIsUnsigned(E->getType()->isUnsignedIntegerType()); - Result = bres; - Info.isEvaluated = isEvaluated; - - return true; + bool bres2; + if (HandleConversionToBool(E->getRHS(), bres2, Info)) { + Result.zextOrTrunc(getIntTypeSizeInBits(E->getType())); + Result.setIsUnsigned(E->getType()->isUnsignedIntegerType()); + if (E->getOpcode() == BinaryOperator::LOr) + Result = bres || bres2; + else + Result = bres && bres2; + return true; + } + } else { + if (HandleConversionToBool(E->getRHS(), bres, Info)) { + // We can't evaluate the LHS; however, sometimes the result + // is determined by the RHS: X && 0 -> 0, X || 1 -> 1. + if (bres == (E->getOpcode() == BinaryOperator::LOr) || + !bres == (E->getOpcode() == BinaryOperator::LAnd)) { + Result.zextOrTrunc(getIntTypeSizeInBits(E->getType())); + Result.setIsUnsigned(E->getType()->isUnsignedIntegerType()); + Result = bres; + Info.isEvaluated = false; + + return true; + } + } } - bool bres2; - if (HandleConversionToBool(E->getRHS(), bres2, Info)) { - Result.zextOrTrunc(getIntTypeSizeInBits(E->getType())); - Result.setIsUnsigned(E->getType()->isUnsignedIntegerType()); - if (E->getOpcode() == BinaryOperator::LOr) - Result = bres || bres2; - else - Result = bres && bres2; - return true; - } return false; } |