aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-01-29 06:43:41 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-01-29 06:43:41 +0000
commit4087e24f73d05d96ac2d259679751d054d3ddfbc (patch)
treef8687fd2865ff9a9f91a166200dbf344ce92399e /lib/AST/ExprConstant.cpp
parent107dc76180733ecf04848a47299748f9755cdb62 (diff)
Evaluate ==,!= for complex types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63280 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index eae3f64ac9..9798520507 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -729,6 +729,50 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
QualType LHSTy = E->getLHS()->getType();
QualType RHSTy = E->getRHS()->getType();
+
+ if (LHSTy->isAnyComplexType()) {
+ assert(RHSTy->isAnyComplexType() && "Invalid comparison");
+ APValue LHS, RHS;
+
+ if (!EvaluateComplex(E->getLHS(), LHS, Info))
+ return false;
+
+ if (!EvaluateComplex(E->getRHS(), RHS, Info))
+ return false;
+
+ if (LHS.isComplexFloat()) {
+ APFloat::cmpResult CR_r =
+ LHS.getComplexFloatReal().compare(RHS.getComplexFloatReal());
+ APFloat::cmpResult CR_i =
+ LHS.getComplexFloatImag().compare(RHS.getComplexFloatImag());
+
+ Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
+ if (E->getOpcode() == BinaryOperator::EQ)
+ Result = (CR_r == APFloat::cmpEqual &&
+ CR_i == APFloat::cmpEqual);
+ else if (E->getOpcode() == BinaryOperator::NE)
+ Result = ((CR_r == APFloat::cmpGreaterThan ||
+ CR_r == APFloat::cmpLessThan) &&
+ (CR_i == APFloat::cmpGreaterThan ||
+ CR_i == APFloat::cmpLessThan));
+ else
+ assert(0 && "Invalid complex compartison.");
+ Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
+ return true;
+ } else {
+ Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+ if (E->getOpcode() == BinaryOperator::EQ)
+ Result = (LHS.getComplexIntReal() == RHS.getComplexIntReal() &&
+ LHS.getComplexIntImag() == RHS.getComplexIntImag());
+ else if (E->getOpcode() == BinaryOperator::NE)
+ Result = (LHS.getComplexIntReal() != RHS.getComplexIntReal() ||
+ LHS.getComplexIntImag() != RHS.getComplexIntImag());
+ else
+ assert(0 && "Invalid complex compartison.");
+ Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
+ return true;
+ }
+ }
if (LHSTy->isRealFloatingType() &&
RHSTy->isRealFloatingType()) {