This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Don't warn if taking the absolute value of a difference of unsigned values.
Needs ReviewPublic

Authored by cdavis5x on Jun 4 2015, 5:23 PM.

Details

Reviewers
rtrieu
Summary

While any given unsigned value usually cannot be negative, a difference
of two unsigned values can be negative iff the subtrahend (i.e. the
second value) is greater than the minuend. For this reason, it is common
to wrap a difference like this in an abs(3) call. Don't warn on these
cases.

Diff Detail

Event Timeline

cdavis5x updated this revision to Diff 27165.Jun 4 2015, 5:23 PM
cdavis5x retitled this revision from to [Sema] Don't warn if taking the absolute value of a difference of unsigned values..
cdavis5x updated this object.
cdavis5x edited the test plan for this revision. (Show Details)
cdavis5x added a reviewer: rtrieu.
cdavis5x added a subscriber: Unknown Object (MLST).

I think you CCed the wrong mailing list. I think you want cfe-commits.

cdavis5x added a subscriber: Unknown Object (MLST).Jun 4 2015, 7:04 PM

Oops, you're right. Now I've added the correct list, but how do I get llvm-commits unsubscribed?

rsmith added a subscriber: rsmith.Jun 4 2015, 10:52 PM

The difference of two unsigned promoted types is also unsigned, so cannot be negative. Perhaps we should word the warning differently in this case, but a warning does seem justified.