This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/51712] -Wtype-limits should not trigger for types of implementation-defined signedness
- From: "jrnieder at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 26 Mar 2012 20:12:17 +0000
- Subject: [Bug c/51712] -Wtype-limits should not trigger for types of implementation-defined signedness
- Auto-submitted: auto-generated
- References: <bug-51712-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51712
--- Comment #2 from Jonathan Nieder <jrnieder at gmail dot com> 2012-03-26 20:12:17 UTC ---
Clang does not consider "arg >= FOO" to be a comparison against 0.
| commit e3b159c0
| Author: Ted Kremenek <kremenek@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>
|
| git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114695
91177308-0d34-0410-b5e6-96231b3b80d8
|
| diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
| index 790e7671..c4e86875 100644
| --- a/lib/Sema/SemaChecking.cpp
| +++ b/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;
| }
[...]