Enhance -Wtautological-constant-out-of-range-compare to include the name of the enum constant.

This is QoI.  Fixes <rdar://problem/13076064>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177190 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index dd797bb..b566488 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -4495,9 +4495,22 @@
     else // op == BO_GT || op == BO_GE
       IsTrue = PositiveConstant;
   }
-  SmallString<16> PrettySourceValue(Value.toString(10));
+
+  // If this is a comparison to an enum constant, include that
+  // constant in the diagnostic.
+  const EnumConstantDecl *ED = 0;
+  if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Constant))
+    ED = dyn_cast<EnumConstantDecl>(DR->getDecl());
+
+  SmallString<64> PrettySourceValue;
+  llvm::raw_svector_ostream OS(PrettySourceValue);
+  if (ED)
+    OS << '\'' << ED->getName() << "' (" << Value << ")";
+  else
+    OS << Value;
+
   S.Diag(E->getOperatorLoc(), diag::warn_out_of_range_compare)
-      << PrettySourceValue << OtherT << IsTrue
+      << OS.str() << OtherT << IsTrue
       << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
 }