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/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td @@ -5898,14 +5898,14 @@ InGroup, DefaultIgnore; def warn_lunsigned_always_true_comparison : Warning< "comparison of unsigned%select{| enum}2 expression %0 is always %1">, - InGroup; + InGroup; 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; def warn_runsigned_always_true_comparison : Warning< "comparison of %0 unsigned%select{| enum}2 expression is always %1">, - InGroup; + InGroup; def warn_comparison_of_mixed_enum_types : Warning< "comparison of two values with different enumeration types" "%diff{ ($ and $)|}0,1">, 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; +}