<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 15, 2013, at 14:50 , Ted Kremenek <<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">Author: kremenek<br>Date: Fri Mar 15 16:50:10 2013<br>New Revision: 177190<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=177190&view=rev">http://llvm.org/viewvc/llvm-project?rev=177190&view=rev</a><br>Log:<br>Enhance -Wtautological-constant-out-of-range-compare to include the name of the enum constant.<br><br>This is QoI.  Fixes <<a href="rdar://problem/13076064">rdar://problem/13076064</a>>.<br><br>Modified:<br>   cfe/trunk/lib/Sema/SemaChecking.cpp<br>   cfe/trunk/test/Sema/compare.c<br>   cfe/trunk/test/SemaCXX/compare.cpp<br>   cfe/trunk/test/SemaCXX/warn-enum-compare.cpp<br><br>Modified: cfe/trunk/lib/Sema/SemaChecking.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=177190&r1=177189&r2=177190&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=177190&r1=177189&r2=177190&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)<br>+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Mar 15 16:50:10 2013<br>@@ -4495,9 +4495,22 @@ static void DiagnoseOutOfRangeComparison<br>    else // op == BO_GT || op == BO_GE<br>      IsTrue = PositiveConstant;<br>  }<br>-  SmallString<16> PrettySourceValue(Value.toString(10));<br>+<br>+  // If this is a comparison to an enum constant, include that<br>+  // constant in the diagnostic.<br>+  const EnumConstantDecl *ED = 0;<br>+  if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Constant))<br>+    ED = dyn_cast<EnumConstantDecl>(DR->getDecl());<br>+<br>+  SmallString<64> PrettySourceValue;<br>+  llvm::raw_svector_ostream OS(PrettySourceValue);<br>+  if (ED)<br>+    OS << '\'' << ED->getName() << "' (" << Value << ")";<br>+  else<br>+    OS << Value;<br></div></blockquote><div><br></div><div>This could just be 'OS << *ED << " (" << Value << ")", right?</div><div><br></div><div>Also, it's possible you could bake this into the diagnostic format, but I guess that's probably not worth it.</div><div><br></div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">  S.Diag(E->getOperatorLoc(), diag::warn_out_of_range_compare)<br>-      << PrettySourceValue << OtherT << IsTrue<br>+      << OS.str() << OtherT << IsTrue<br>      << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();<br>}<br><br><br>Modified: cfe/trunk/test/Sema/compare.c<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=177190&r1=177189&r2=177190&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=177190&r1=177189&r2=177190&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/Sema/compare.c (original)<br>+++ cfe/trunk/test/Sema/compare.c Fri Mar 15 16:50:10 2013<br>@@ -93,8 +93,8 @@ int ints(long a, unsigned long b) {<br>         // (C,b)<br>         (C == (unsigned long) b) +<br>         (C == (unsigned int) b) +<br>-         (C == (unsigned short) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned short' is always false}}<br>-         (C == (unsigned char) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned char' is always false}}<br>+         (C == (unsigned short) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned short' is always false}}<br>+         (C == (unsigned char) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned char' is always false}}<br>         ((long) C == b) +<br>         ((int) C == b) +<br>         ((short) C == b) +<br>@@ -105,8 +105,8 @@ int ints(long a, unsigned long b) {<br>         ((signed char) C == (unsigned char) b) +<br>         (C < (unsigned long) b) +<br>         (C < (unsigned int) b) +<br>-         (C < (unsigned short) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned short' is always false}}<br>-         (C < (unsigned char) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned char' is always false}}<br>+         (C < (unsigned short) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned short' is always false}}<br>+         (C < (unsigned char) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned char' is always false}}<br>         ((long) C < b) +<br>         ((int) C < b) +<br>         ((short) C < b) +<br>@@ -123,8 +123,8 @@ int ints(long a, unsigned long b) {<br>         (a == (unsigned char) C) +<br>         ((long) a == C) +<br>         ((int) a == C) +<br>-         ((short) a == C) + // expected-warning {{comparison of constant 65536 with expression of type 'short' is always false}}<br>-         ((signed char) a == C) + // expected-warning {{comparison of constant 65536 with expression of type 'signed char' is always false}}<br>+         ((short) a == C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'short' is always false}}<br>+         ((signed char) a == C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'signed char' is always false}}<br>         ((long) a == (unsigned long) C) +<br>         ((int) a == (unsigned int) C) +<br>         ((short) a == (unsigned short) C) +<br>@@ -135,8 +135,8 @@ int ints(long a, unsigned long b) {<br>         (a < (unsigned char) C) +<br>         ((long) a < C) +<br>         ((int) a < C) +<br>-         ((short) a < C) + // expected-warning {{comparison of constant 65536 with expression of type 'short' is always true}}<br>-         ((signed char) a < C) + // expected-warning {{comparison of constant 65536 with expression of type 'signed char' is always true}}<br>+         ((short) a < C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'short' is always true}}<br>+         ((signed char) a < C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'signed char' is always true}}<br>         ((long) a < (unsigned long) C) +  // expected-warning {{comparison of integers of different signs}}<br>         ((int) a < (unsigned int) C) +  // expected-warning {{comparison of integers of different signs}}<br>         ((short) a < (unsigned short) C) +<br><br>Modified: cfe/trunk/test/SemaCXX/compare.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=177190&r1=177189&r2=177190&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=177190&r1=177189&r2=177190&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/SemaCXX/compare.cpp (original)<br>+++ cfe/trunk/test/SemaCXX/compare.cpp Fri Mar 15 16:50:10 2013<br>@@ -89,8 +89,8 @@ int test0(long a, unsigned long b) {<br>         // (C,b)<br>         (C == (unsigned long) b) +<br>         (C == (unsigned int) b) +<br>-         (C == (unsigned short) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned short' is always false}}<br>-         (C == (unsigned char) b) +  // expected-warning {{comparison of constant 65536 with expression of type 'unsigned char' is always false}}<br>+         (C == (unsigned short) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned short' is always false}}<br>+         (C == (unsigned char) b) +  // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned char' is always false}}<br>         ((long) C == b) +<br>         ((int) C == b) +<br>         ((short) C == b) +<br>@@ -101,8 +101,8 @@ int test0(long a, unsigned long b) {<br>         ((signed char) C == (unsigned char) b) +<br>         (C < (unsigned long) b) +<br>         (C < (unsigned int) b) +<br>-         (C < (unsigned short) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned short' is always false}}<br>-         (C < (unsigned char) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned char' is always false}}<br>+         (C < (unsigned short) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned short' is always false}}<br>+         (C < (unsigned char) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned char' is always false}}<br>         ((long) C < b) +<br>         ((int) C < b) +<br>         ((short) C < b) +<br>@@ -119,8 +119,8 @@ int test0(long a, unsigned long b) {<br>         (a == (unsigned char) C) +<br>         ((long) a == C) +<br>         ((int) a == C) +<br>-         ((short) a == C) + // expected-warning {{comparison of constant 65536 with expression of type 'short' is always false}}<br>-         ((signed char) a == C) + // expected-warning {{comparison of constant 65536 with expression of type 'signed char' is always false}}<br>+         ((short) a == C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'short' is always false}}<br>+         ((signed char) a == C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'signed char' is always false}}<br>         ((long) a == (unsigned long) C) +<br>         ((int) a == (unsigned int) C) +<br>         ((short) a == (unsigned short) C) +<br>@@ -131,8 +131,8 @@ int test0(long a, unsigned long b) {<br>         (a < (unsigned char) C) +<br>         ((long) a < C) +<br>         ((int) a < C) +<br>-         ((short) a < C) + // expected-warning {{comparison of constant 65536 with expression of type 'short' is always true}}<br>-         ((signed char) a < C) + // expected-warning {{comparison of constant 65536 with expression of type 'signed char' is always true}}<br>+         ((short) a < C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'short' is always true}}<br>+         ((signed char) a < C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'signed char' is always true}}<br>         ((long) a < (unsigned long) C) +  // expected-warning {{comparison of integers of different signs}}<br>         ((int) a < (unsigned int) C) +  // expected-warning {{comparison of integers of different signs}}<br>         ((short) a < (unsigned short) C) +<br><br>Modified: cfe/trunk/test/SemaCXX/warn-enum-compare.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-enum-compare.cpp?rev=177190&r1=177189&r2=177190&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-enum-compare.cpp?rev=177190&r1=177189&r2=177190&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/SemaCXX/warn-enum-compare.cpp (original)<br>+++ cfe/trunk/test/SemaCXX/warn-enum-compare.cpp Fri Mar 15 16:50:10 2013<br>@@ -39,8 +39,8 @@ void test () {<br>  while (b == c);<br>  while (B1 == name1::B2);<br>  while (B2 == name2::B1);<br>-  while (x == AnonAA); // expected-warning {{comparison of constant 42 with expression of type 'Foo' is always false}}<br>-  while (AnonBB == y); // expected-warning {{comparison of constant 45 with expression of type 'Bar' is always false}}<br>+  while (x == AnonAA); // expected-warning {{comparison of constant 'AnonAA' (42) with expression of type 'Foo' is always false}}<br>+  while (AnonBB == y); // expected-warning {{comparison of constant 'AnonBB' (45) with expression of type 'Bar' is always false}}<br>  while (AnonAA == AnonAB);<br>  while (AnonAB == AnonBA);<br>  while (AnonBB == AnonAA);<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></blockquote></div><br></body></html>