]> granicus.if.org Git - clang/commitdiff
implement support for __extension__, make sure the result of a
authorChris Lattner <sabre@nondot.org>
Fri, 11 Jul 2008 19:29:32 +0000 (19:29 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 11 Jul 2008 19:29:32 +0000 (19:29 +0000)
comparison has the right width.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53469 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp

index 662104ec701885557910a5289cdca8e72e96b06d..04f1572cb37e20432901037945a157f5e58cf2a1 100644 (file)
@@ -220,6 +220,10 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
     break;
   case BinaryOperator::Add: Result += RHS; break;
   case BinaryOperator::Sub: Result -= RHS; break;
+  case BinaryOperator::And: Result &= RHS; break;
+  case BinaryOperator::Xor: Result ^= RHS; break;
+  case BinaryOperator::Or:  Result |= RHS; break;
+      
   case BinaryOperator::Shl:
     Result <<= (unsigned)RHS.getLimitedValue(Result.getBitWidth()-1);
     break;
@@ -227,16 +231,30 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
     Result >>= (unsigned)RHS.getLimitedValue(Result.getBitWidth()-1);
     break;
       
-  // FIXME: Need to set the result width?
-  case BinaryOperator::LT:  Result = Result < RHS; break;
-  case BinaryOperator::GT:  Result = Result > RHS; break;
-  case BinaryOperator::LE:  Result = Result <= RHS; break;
-  case BinaryOperator::GE:  Result = Result >= RHS; break;
-  case BinaryOperator::EQ:  Result = Result == RHS; break;
-  case BinaryOperator::NE:  Result = Result != RHS; break;
-  case BinaryOperator::And: Result &= RHS; break;
-  case BinaryOperator::Xor: Result ^= RHS; break;
-  case BinaryOperator::Or:  Result |= RHS; break;
+  case BinaryOperator::LT:
+    Result = Result < RHS;
+    Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+    break;
+  case BinaryOperator::GT:
+    Result = Result > RHS;
+    Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+    break;
+  case BinaryOperator::LE:
+    Result = Result <= RHS;
+    Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+    break;
+  case BinaryOperator::GE:
+    Result = Result >= RHS;
+    Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+    break;
+  case BinaryOperator::EQ:
+    Result = Result == RHS;
+    Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+    break;
+  case BinaryOperator::NE:
+    Result = Result != RHS;
+    Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+    break;
     
   case BinaryOperator::Comma:
     // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
@@ -293,16 +311,15 @@ bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
       // See C99 6.6p3.
     default:
       return false;
-    case UnaryOperator::Extension:
-      assert(0 && "Handle UnaryOperator::Extension");
-        return false;
     case UnaryOperator::LNot: {
       bool Val = Result == 0;
       Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
       Result = Val;
       break;
     }
+    case UnaryOperator::Extension:
     case UnaryOperator::Plus:
+      // The result is always just the subexpr
       break;
     case UnaryOperator::Minus:
       Result = -Result;