[llvm-branch-commits] [cfe-branch] r114903 - in /cfe/branches/Apple/whitney: lib/Sema/SemaChecking.cpp test/Sema/compare.c

Daniel Dunbar daniel at zuster.org
Mon Sep 27 15:12:55 PDT 2010


Author: ddunbar
Date: Mon Sep 27 17:12:55 2010
New Revision: 114903

URL: http://llvm.org/viewvc/llvm-project?rev=114903&view=rev
Log:
Merge r114695:
--
Author: Ted Kremenek <kremenek at apple.com>
Date:   Thu Sep 23 21:43:44 2010 +0000

    When warning about comparing an unsigned int to being >= 0, don't issue a warning if the zero value was an
    enum or was expanded from a macro.

    Fixes: <rdar://problem/8414119>

Modified:
    cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp
    cfe/branches/Apple/whitney/test/Sema/compare.c

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp?rev=114903&r1=114902&r2=114903&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp Mon Sep 27 17:12:55 2010
@@ -2449,7 +2449,17 @@
 
 void AnalyzeImplicitConversions(Sema &S, Expr *E);
 
-bool IsZero(Sema &S, Expr *E) {
+static bool IsZero(Sema &S, Expr *E) {
+  // Suppress cases where we are comparing against an enum constant.
+  if (const DeclRefExpr *DR =
+      dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
+    if (isa<EnumConstantDecl>(DR->getDecl()))
+      return false;
+
+  // Suppress cases where the '0' value is expanded from a macro.
+  if (E->getLocStart().isMacroID())
+    return false;
+
   llvm::APSInt Value;
   return E->isIntegerConstantExpr(Value, S.Context) && Value == 0;
 }

Modified: cfe/branches/Apple/whitney/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Sema/compare.c?rev=114903&r1=114902&r2=114903&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Sema/compare.c (original)
+++ cfe/branches/Apple/whitney/test/Sema/compare.c Mon Sep 27 17:12:55 2010
@@ -288,3 +288,20 @@
   unsigned x = (i < (1 << power) ? i : 0);
   return x != 3 ? 1 << power : i;
 }
+
+// <rdar://problem/8414119> enum >= (enum)0 comparison should not generate any warnings
+enum rdar8414119_Vals { X, Y, Z };
+#define ZERO 0
+#define CHECK(x) (x >= X)
+void rdar8414119_foo(enum rdar8414119_Vals v) {
+  if (CHECK(v)) // no-warning
+   return;
+  if (v >= X) // no-warning
+   return;
+}
+int rdar8414119_bar(unsigned x) {
+  return x >= ZERO; // no-warning
+}
+#undef ZERO
+#undef CHECK
+





More information about the llvm-branch-commits mailing list