This is an archive of the discontinued LLVM Phabricator instance.

Make rehash(0) work with ubsan's unsigned-integer-overflow.
ClosedPublic

Authored by danalbert on Dec 1 2017, 12:29 PM.

Event Timeline

danalbert created this revision.Dec 1 2017, 12:29 PM
mclow.lists edited edge metadata.Dec 11 2017, 10:26 AM

Dan - I think I need a bit more context here.
How does UBSan get triggered?

danalbert added inline comments.Dec 11 2017, 8:59 PM
include/__hash_table
2141

With rehash(0) this is 0 & (0 - 1), which triggers unsigned-integer-overflow.

mclow.lists accepted this revision.Dec 14 2017, 7:29 AM
mclow.lists added inline comments.
include/__hash_table
2141

Grumble, grumble. That's not UB, that's just UBSan whining.
On the other hand, this doesn't appear to change any behavior, and shuts UBSan up.

This revision is now accepted and ready to land.Dec 14 2017, 7:29 AM
This revision was automatically updated to reflect the committed changes.
danalbert added inline comments.Jan 8 2018, 1:53 PM
include/__hash_table
2141

FWIW, this check isn't enabled in ubsan by default. Android uses it for testing and mititgation in a handful of projects because it does catch errors (stagefright was an unsigned overflow issue). It's good to keep the libc++ headers clean of these issues so we're not dictating the compile flags of libc++ users.