[cfe-dev] [StaticAnalyser][RFC] Loss of sign/precision
Daniel Marjamäki via cfe-dev
cfe-dev at lists.llvm.org
Thu Sep 17 07:09:26 PDT 2015
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 at evidente.se
www.evidente.se
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 150917-sign.diff
Type: text/x-patch
Size: 9347 bytes
Desc: 150917-sign.diff
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150917/5e7e2a07/attachment.bin>
More information about the cfe-dev
mailing list