implement support for __extension__, make sure the result of a
comparison has the right width.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53469 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 662104e..04f1572 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -220,6 +220,10 @@
     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 @@
     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 @@
       // 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;