Fix for PR2501; this patch makes usual arithmetic conversions for 
integers which have the same width and different signedness work 
correctly. (The testcase in PR2501 uses a comparison between long and 
unsigned int).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52853 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 11ca78a..08a2bb1 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1757,6 +1757,41 @@
 }
 
 //===----------------------------------------------------------------------===//
+//                         Integer Predicates
+//===----------------------------------------------------------------------===//
+unsigned ASTContext::getIntWidth(QualType T) {
+  if (T == BoolTy)
+    return 1;
+  // At the moment, only bool has padding bits
+  return (unsigned)getTypeSize(T);
+}
+
+QualType ASTContext::getCorrespondingUnsignedType(QualType T) {
+  assert(T->isSignedIntegerType() && "Unexpected type");
+  if (const EnumType* ETy = T->getAsEnumType())
+    T = ETy->getDecl()->getIntegerType();
+  const BuiltinType* BTy = T->getAsBuiltinType();
+  assert (BTy && "Unexpected signed integer type");
+  switch (BTy->getKind()) {
+  case BuiltinType::Char_S:
+  case BuiltinType::SChar:
+    return UnsignedCharTy;
+  case BuiltinType::Short:
+    return UnsignedShortTy;
+  case BuiltinType::Int:
+    return UnsignedIntTy;
+  case BuiltinType::Long:
+    return UnsignedLongTy;
+  case BuiltinType::LongLong:
+    return UnsignedLongLongTy;
+  default:
+    assert(0 && "Unexpected signed integer type");
+    return QualType();
+  }
+}
+
+
+//===----------------------------------------------------------------------===//
 //                         Serialization Support
 //===----------------------------------------------------------------------===//