[StaticAnalyser][RFC] Loss of sign/precision

Hello!

I am working on a new checker. It will warn if there is loss of sign in assignments/comparisons/multiplications or loss of precision in assignments.

My plan is that it will fix the FP given by Wsign-compare/Wsign-conversion etc. But warn about real bugs using flow sensitive analysis.

For information, you can see half a million Wsign-conversion warnings here (got those when compiling various debian projects):
http://cppcheck.sourceforge.net/devinfo/clang-Weverything/results-sign-conversion.txt

Some test cases:

unsigned char U8;
signed char S8;

void assign(unsigned U, signed S) {
  if (S < -10)
    U8 = S; // expected-warning {{Implicit conversion changes signedness (negative value)}}
  if (U > 300)
    S8 = U; // expected-warning {{Loss of precision}}
  if (S > 10)
    U8 = S;
  if (U < 200)
   S8 = U;
}

void relational(unsigned U, signed S) {
  if (S > 10) {
    if (U < S) {}
  }
  if (S < -10) {
    if (U < S) {} // expected-warning {{Implicit conversion changes signedness (negative value)}}
  }
}

void multiplication(unsigned U, signed S) {
  if (S > 5)
    S = U * S;
  if (S < -10)
    S = U * S; // expected-warning {{Implicit conversion changes signedness (negative value)}}
}

void division(unsigned U, signed S) {
  if (S > 5)
    S = U / S;
  if (S < -10)
    S = U / S; // expected-warning {{Implicit conversion changes signedness (negative value)}}
}

I attach a patch. In my opinion the patch is almost ready to be uploaded to the reviews.llvm.org so feel free to give it a proper review. Any comments?

Best regards,
Daniel Marjamäki

..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden

Mobile: +46 (0)709 12 42 62
E-mail: Daniel.Marjamaki@evidente.se

www.evidente.se

150917-sign.diff (9.13 KB)