[cfe-commits] r114695 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/compare.c
Ted Kremenek
kremenek at apple.com
Thu Sep 23 14:43:45 PDT 2010
Author: kremenek
Date: Thu Sep 23 16:43:44 2010
New Revision: 114695
URL: http://llvm.org/viewvc/llvm-project?rev=114695&view=rev
Log:
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/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/compare.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=114695&r1=114694&r2=114695&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep 23 16:43:44 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/trunk/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=114695&r1=114694&r2=114695&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Thu Sep 23 16:43:44 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 cfe-commits
mailing list