summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-09-23 21:43:44 +0000
committerTed Kremenek <kremenek@apple.com>2010-09-23 21:43:44 +0000
commit6274be47faafff014e607f3e26e7779fa75e90e8 (patch)
treee76e05cea6a5ca87b1fda7f2f0a7b3aa7f6b90c4 /clang/lib/Sema/SemaChecking.cpp
parent24fb1d03d3fb3770f5e6a53f26a693a02ca4d57f (diff)
downloadbcm5719-llvm-6274be47faafff014e607f3e26e7779fa75e90e8.tar.gz
bcm5719-llvm-6274be47faafff014e607f3e26e7779fa75e90e8.zip
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> llvm-svn: 114695
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 790e7671ed9..c4e86875ed8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2449,7 +2449,17 @@ bool IsSameFloatAfterCast(const APValue &value,
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;
}
OpenPOWER on IntegriCloud