Extend tautological compare and bool conversion warnings to undefined pointer operations. These are cases where all defined behavior will give the expression one value, while the other value can only result from undefined behavior, which the optimizer can remove. These cases are addresses of references and the this pointer. This warning was requested in PR19899 in response to commit r209723.
Details
Diff Detail
Event Timeline
include/clang/Basic/DiagnosticSemaKinds.td | ||
---|---|---|
2394 | Should these really all be DefaultIgnore if we're optimizing these checks away? |
Some suggestions on diagnostic wording.
include/clang/Basic/DiagnosticSemaKinds.td | ||
---|---|---|
2392–2393 | "undefined contexts" is rather unclear here. Maybe something like: "'this' pointer cannot be null in well-defined C++ code; comparison may be removed" (I don't like "during optimization" either, since it suggests we guarantee to leave this alone at -O0) | |
2396–2398 | Likewise: "reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be removed" |
Make warnings on by default, change wording of warnings, disable warnings in some analysis tests.
LGTM with some minor diagnostic tweaks.
include/clang/Basic/DiagnosticSemaKinds.td | ||
---|---|---|
2393 | "assumed to always convert to" would sound better to me. Also, assumed to always convert to 'true' rather than assumed to always convert to a true value to avoid people wondering what "a true value" is (cf. "a true Scotsman"). Likewise I'd suggest putting the %select's below into single quotes. | |
2409 | Typo "maybe be" should be "may be" |
"undefined contexts" is rather unclear here. Maybe something like:
(I don't like "during optimization" either, since it suggests we guarantee to leave this alone at -O0)