Clang static analysis results for dmd
Walter Bright
newshound2 at digitalmars.com
Thu Jul 28 16:23:22 PDT 2011
On 7/28/2011 3:27 PM, bearophile wrote:
> In Clang those tests aren't a standard part of the C or C++ languages. They
> are extra tests, like a lint tool built in the compiler, and they aren't a
> part of the normal compilation (if you use --analyze it doesn't produce a
> compiled binary, but an HTML of the test results).
If they are part of the compiler, I guarantee you that people will regard it as
a standard part of the language, and the complaints about false positives will
cause problems.
> Some Dead code, Idempotent operation:
Dead code is not a bug. It's more of a stylistic issue, and sometimes that
"dead" code is needed in other code that has been #if'd out. The compiler
complaining about dead code is also a nuisance when turning on and off sections
of code that is a normal part of the dev process.
> Is Clang correct there, or are those false positives? If it's correct then
> I'd like the D compiler to tell me 100% of those I have listed here, even if
> not even one of those is a real bug.
I've been slowly going through the reports, and so far all of them have been
false positives. Don found one that's a real bug, but I haven't gotten to it yet.
Here's an example of a false positive - clang complains the comparison is
idempotent:
size_t e2factor;
...
if (e2factor == (int)e2factor)
For a 32 bit compile, yes, it's idempotent. But not for a 64 bit compile! I
*want* it to be a no-op for a 32 bit compile and to become active in a 64 bit
compile.
Of course, I could also use an ugly #ifdef, but I like that little idiom, it
works, and it is correct. I know why clang is doing what it is doing, but that
shows a weakness in its static analysis.
There are other false positives for things like assigning an uninitialized value
to a field in a data structure that will never be used in the cases where it is
uninitialized. I could add a conditional, but that's slower than just assigning
it anyway. Trying to figure these things out with static analysis is impossible
- it would be solving the halting problem - hence you're stuck with false positives.
More information about the Digitalmars-d
mailing list