[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 8 06:44:14 PDT 2017
lebedev.ri updated this revision to Diff 114351.
lebedev.ri edited the summary of this revision.
lebedev.ri added a comment.
Added test.
Repository:
rL LLVM
https://reviews.llvm.org/D37620
Files:
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
test/Sema/tautological-unsigned-zero-compare.c
Index: test/Sema/tautological-unsigned-zero-compare.c
===================================================================
--- /dev/null
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -0,0 +1,48 @@
+// 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;
+}
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ 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: include/clang/Basic/DiagnosticGroups.td
===================================================================
--- include/clang/Basic/DiagnosticGroups.td
+++ 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]>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37620.114351.patch
Type: text/x-patch
Size: 4035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170908/89d471fb/attachment-0001.bin>
More information about the cfe-commits
mailing list