[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 06:58:14 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL312792: [Sema] Put tautological comparison of unsigned and zero into it's own flag (authored by lebedevri).

Changed prior to commit:
  https://reviews.llvm.org/D37620?vs=114351&id=114358#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37620

Files:
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5898,14 +5898,14 @@
   InGroup<SignCompare>, DefaultIgnore;
 def warn_lunsigned_always_true_comparison : Warning<
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
-  InGroup<TautologicalCompare>;
+  InGroup<TautologicalUnsignedZeroCompare>;
 def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup<TautologicalOutOfRangeCompare>;
 def warn_runsigned_always_true_comparison : Warning<
   "comparison of %0 unsigned%select{| enum}2 expression is always %1">,
-  InGroup<TautologicalCompare>;
+  InGroup<TautologicalUnsignedZeroCompare>;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
Index: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td
@@ -427,12 +427,14 @@
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
+def TautologicalUnsignedZeroCompare : DiagGroup<"tautological-unsigned-zero-compare">;
 def TautologicalOutOfRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
 def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
-                                    [TautologicalOutOfRangeCompare,
+                                    [TautologicalUnsignedZeroCompare,
+                                     TautologicalOutOfRangeCompare,
                                      TautologicalPointerCompare,
                                      TautologicalOverlapCompare,
                                      TautologicalUndefinedCompare]>;
Index: cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
===================================================================
--- cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
+++ cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify %s
+
+unsigned value(void);
+
+int main() {
+  unsigned un = value();
+
+#ifdef TEST
+  if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+    return 0;
+  if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+    return 0;
+  if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+    return 0;
+  if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
+    return 0;
+  if (un < 0U) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+    return 0;
+  if (un >= 0U) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+    return 0;
+  if (0U <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+    return 0;
+  if (0U > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
+    return 0;
+#else
+// expected-no-diagnostics
+  if (un < 0)
+    return 0;
+  if (un >= 0)
+    return 0;
+  if (0 <= un)
+    return 0;
+  if (0 > un)
+    return 0;
+  if (un < 0U)
+    return 0;
+  if (un >= 0U)
+    return 0;
+  if (0U <= un)
+    return 0;
+  if (0U > un)
+    return 0;
+#endif
+
+  return 1;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37620.114358.patch
Type: text/x-patch
Size: 4061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170908/2677e007/attachment-0001.bin>


More information about the cfe-commits mailing list