This is an archive of the discontinued LLVM Phabricator instance.

Add warnings for undefined behaviors with pointers
ClosedPublic

Authored by rtrieu on Jun 2 2014, 9:25 PM.

Details

Reviewers
rsmith
Summary

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.

Diff Detail

Event Timeline

rtrieu updated this revision to Diff 10040.Jun 2 2014, 9:25 PM
rtrieu retitled this revision from to Add warnings for undefined behaviors with pointers.
rtrieu updated this object.
rtrieu edited the test plan for this revision. (Show Details)
rtrieu added a subscriber: Unknown Object (MLST).
rnk added a subscriber: rnk.Jun 3 2014, 11:12 AM
rnk added inline comments.
include/clang/Basic/DiagnosticSemaKinds.td
2394

Should these really all be DefaultIgnore if we're optimizing these checks away?

rsmith added a subscriber: rsmith.Jun 3 2014, 1:06 PM

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"
rtrieu updated this revision to Diff 10066.Jun 3 2014, 3:32 PM

Make warnings on by default, change wording of warnings, disable warnings in some analysis tests.

rsmith added inline comments.Jun 3 2014, 4:43 PM
include/clang/Basic/DiagnosticSemaKinds.td
2392–2393

Typo 'covnerted'.

Maybe "pointer may be assumed to always convert to 'true'"?

2395

Typo "dereference", "well-define".

2405

Perhaps "may be assumed to always evaluate to %select{...}".

rtrieu updated this revision to Diff 10074.Jun 3 2014, 5:53 PM

Fix typos and update wording.

rsmith accepted this revision.Jun 5 2014, 5:00 PM
rsmith added a reviewer: rsmith.

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"

This revision is now accepted and ready to land.Jun 5 2014, 5:00 PM
rtrieu closed this revision.Jun 6 2014, 2:48 PM

Committed in r210372