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

Eitan Adler lists at eitanadler.com
Sun Jan 15 22:23:10 PST 2012


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.

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



More information about the cfe-commits mailing list