[cfe-commits] [patch] Don't report signness compare when it can't be reached

Douglas Gregor dgregor at apple.com
Mon Apr 30 18:54:33 PDT 2012


On Jan 15, 2012, at 10:23 PM, Eitan Adler <lists at eitanadler.com> wrote:

> This patch fixes a false positive of -Wsign-compare when you have code
> that evaluates to
> 
> unsigned int a;
> if (0 && -1 > a)
> 
> This was found in real life code in a check that looks like
> if ((sizeof(off_t) > sizeof(size_t)) && sb.st_size > SIZE_MAX)
> 
> On an amd64 system the latter is always false (and generates the
> warning) but on an i386 system it is possible to hit the code.
> 
> Thank you to chandlerc for encouraging me to try fixing this one myself.

I'm so sorry this got lost. Committed as r155876, thanks!

	- Doug

> Index: SemaChecking.cpp
> ===================================================================
> --- SemaChecking.cpp	(revision 148228)
> +++ SemaChecking.cpp	(working copy)
> @@ -3567,9 +3567,9 @@
>       return;
>   }
> 
> -  S.Diag(E->getOperatorLoc(), diag::warn_mixed_sign_comparison)
> +  S.DiagRuntimeBehavior(E->getOperatorLoc(), E,
> S.PDiag(diag::warn_mixed_sign_comparison)
>     << LHS->getType() << RHS->getType()
> -    << LHS->getSourceRange() << RHS->getSourceRange();
> +    << LHS->getSourceRange() << RHS->getSourceRange());
> }
> 
> /// Analyzes an attempt to assign the given value to a bitfield.
> 
> 
> -- 
> Eitan Adler
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list