r313683 - Revert "[Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare"

Roman Lebedev via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 19 14:40:41 PDT 2017


Author: lebedevri
Date: Tue Sep 19 14:40:41 2017
New Revision: 313683

URL: http://llvm.org/viewvc/llvm-project?rev=313683&view=rev
Log:
Revert "[Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare"

This reverts commit r313677.

Buildbots fail with assertion failure
Failing Tests (7):
    Clang :: Analysis/null-deref-ps.c
    Clang :: CodeGen/enum.c
    Clang :: Sema/compare.c
    Clang :: Sema/outof-range-constant-compare.c
    Clang :: Sema/tautological-unsigned-enum-zero-compare.c
    Clang :: Sema/tautological-unsigned-zero-compare.c
    Clang :: SemaCXX/compare.cpp

Removed:
    cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/compare.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=313683&r1=313682&r2=313683&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Sep 19 14:40:41 2017
@@ -429,14 +429,12 @@ def StringPlusInt : DiagGroup<"string-pl
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
 def TautologicalUnsignedZeroCompare : DiagGroup<"tautological-unsigned-zero-compare">;
-def TautologicalUnsignedEnumZeroCompare : DiagGroup<"tautological-unsigned-enum-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",
                                     [TautologicalUnsignedZeroCompare,
-                                     TautologicalUnsignedEnumZeroCompare,
                                      TautologicalOutOfRangeCompare,
                                      TautologicalPointerCompare,
                                      TautologicalOverlapCompare,

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313683&r1=313682&r2=313683&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 19 14:40:41 2017
@@ -5906,26 +5906,19 @@ def note_typecheck_assign_const : Note<
   "member function %q1 is declared const here|"
   "%select{|nested }1data member %2 declared const here}0">;
 
-def warn_lunsigned_always_true_comparison : Warning<
-  "comparison of unsigned expression %0 is always %select{false|true}1">,
-  InGroup<TautologicalUnsignedZeroCompare>;
-def warn_runsigned_always_true_comparison : Warning<
-  "comparison of %0 unsigned expression is always %select{false|true}1">,
-  InGroup<TautologicalUnsignedZeroCompare>;
-def warn_lunsigned_enum_always_true_comparison : Warning<
-  "comparison of unsigned enum expression %0 is always %select{false|true}1">,
-  InGroup<TautologicalUnsignedEnumZeroCompare>;
-def warn_runsigned_enum_always_true_comparison : Warning<
-  "comparison of %0 unsigned enum expression is always %select{false|true}1">,
-  InGroup<TautologicalUnsignedEnumZeroCompare>;
-
 def warn_mixed_sign_comparison : Warning<
   "comparison of integers of different signs: %0 and %1">,
   InGroup<SignCompare>, DefaultIgnore;
+def warn_lunsigned_always_true_comparison : Warning<
+  "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
+  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<TautologicalUnsignedZeroCompare>;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=313683&r1=313682&r2=313683&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 19 14:40:41 2017
@@ -8583,7 +8583,7 @@ bool CheckTautologicalComparisonWithZero
 
   // bool values are handled by DiagnoseOutOfRangeComparison().
 
-  BinaryOperatorKind Op = E->getOpcode();
+  BinaryOperatorKind op = E->getOpcode();
   if (E->isValueDependent())
     return false;
 
@@ -8592,30 +8592,22 @@ bool CheckTautologicalComparisonWithZero
 
   bool Match = true;
 
-  if (Op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
-    S.Diag(E->getOperatorLoc(),
-           HasEnumType(LHS) ? diag::warn_lunsigned_enum_always_true_comparison
-                            : diag::warn_lunsigned_always_true_comparison)
-        << "< 0"
-        << "false" << LHS->getSourceRange() << RHS->getSourceRange();
-  } else if (Op == BO_GE && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
-    S.Diag(E->getOperatorLoc(),
-           HasEnumType(LHS) ? diag::warn_lunsigned_enum_always_true_comparison
-                            : diag::warn_lunsigned_always_true_comparison)
-        << ">= 0"
-        << "true" << LHS->getSourceRange() << RHS->getSourceRange();
-  } else if (Op == BO_GT && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
-    S.Diag(E->getOperatorLoc(),
-           HasEnumType(RHS) ? diag::warn_runsigned_enum_always_true_comparison
-                            : diag::warn_runsigned_always_true_comparison)
-        << "0 >"
-        << "false" << LHS->getSourceRange() << RHS->getSourceRange();
-  } else if (Op == BO_LE && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
-    S.Diag(E->getOperatorLoc(),
-           HasEnumType(RHS) ? diag::warn_runsigned_enum_always_true_comparison
-                            : diag::warn_runsigned_always_true_comparison)
-        << "0 <="
-        << "true" << LHS->getSourceRange() << RHS->getSourceRange();
+  if (op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
+    S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
+      << "< 0" << "false" << HasEnumType(LHS)
+      << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_GE && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
+    S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
+      << ">= 0" << "true" << HasEnumType(LHS)
+      << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_GT && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
+    S.Diag(E->getOperatorLoc(), diag::warn_runsigned_always_true_comparison)
+      << "0 >" << "false" << HasEnumType(RHS)
+      << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_LE && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
+    S.Diag(E->getOperatorLoc(), diag::warn_runsigned_always_true_comparison)
+      << "0 <=" << "true" << HasEnumType(RHS)
+      << LHS->getSourceRange() << RHS->getSourceRange();
   } else
     Match = false;
 

Modified: cfe/trunk/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=313683&r1=313682&r2=313683&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Tue Sep 19 14:40:41 2017
@@ -308,59 +308,8 @@ int rdar8414119_bar(unsigned x) {
 int rdar8511238() {
   enum A { A_foo, A_bar };
   enum A a;
-
-  if (a == 0)
-      return 0;
-  if (a != 0)
-      return 0;
   if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-      return 0;
-  if (a <= 0)
-      return 0;
-  if (a > 0)
-      return 0;
-  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
-      return 0;
-
-  if (0 == a)
-      return 0;
-  if (0 != a)
-      return 0;
-  if (0 < a)
-      return 0;
-  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
-      return 0;
-  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
-      return 0;
-  if (0 >= a)
-      return 0;
-
-  if (a == 0U)
-      return 0;
-  if (a != 0U)
-      return 0;
-  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-      return 0;
-  if (a <= 0U)
-      return 0;
-  if (a > 0U)
-      return 0;
-  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
-      return 0;
-
-  if (0U == a)
-      return 0;
-  if (0U != a)
-      return 0;
-  if (0U < a)
-      return 0;
-  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
-      return 0;
-  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
-      return 0;
-  if (0U >= a)
-      return 0;
-
+    return 0;
   return 20;
 }
 

Removed: cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.c?rev=313682&view=auto
==============================================================================
--- cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.c (original)
+++ cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.c (removed)
@@ -1,46 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-enum-zero-compare -verify %s
-
-int main() {
-  enum A { A_foo, A_bar };
-  enum A a;
-
-#ifdef TEST
-  if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-    return 0;
-  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
-    return 0;
-  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
-    return 0;
-  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
-    return 0;
-  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-    return 0;
-  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
-    return 0;
-  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
-    return 0;
-  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
-    return 0;
-#else
-  // expected-no-diagnostics
-  if (a < 0)
-    return 0;
-  if (a >= 0)
-    return 0;
-  if (0 <= a)
-    return 0;
-  if (0 > a)
-    return 0;
-  if (a < 0U)
-    return 0;
-  if (a >= 0U)
-    return 0;
-  if (0U <= a)
-    return 0;
-  if (0U > a)
-    return 0;
-#endif
-
-  return 1;
-}




More information about the cfe-commits mailing list