This is an archive of the discontinued LLVM Phabricator instance.

ADT: Fix pointer comparison UB in SmallVector
ClosedPublic

Authored by dexonsmith on Dec 23 2020, 1:24 PM.

Details

Summary

The standard requires comparisons of pointers to unrelated storage to
use std::less. Split out some helpers that do that and update all the
code that was comparing using < and friends (mostly assertions).

Diff Detail

Event Timeline

dexonsmith created this revision.Dec 23 2020, 1:24 PM
dexonsmith requested review of this revision.Dec 23 2020, 1:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2020, 1:24 PM
dexonsmith added inline comments.Dec 23 2020, 1:26 PM
llvm/include/llvm/ADT/SmallVector.h
636

Note that this assertion (and a couple of others) would start firing on I == this->end(), but in each case that has been handled by an early return.

dblaikie accepted this revision.Dec 23 2020, 3:02 PM
dblaikie added inline comments.
llvm/include/llvm/ADT/SmallVector.h
142
155

Should be able to use std::less<>, I think? Though given the need for 3 calls, probably still nice to alias it like you have.

This revision is now accepted and ready to land.Dec 23 2020, 3:02 PM
This revision was landed with ongoing or failed builds.Jan 11 2021, 3:31 PM
This revision was automatically updated to reflect the committed changes.
dexonsmith marked 2 inline comments as done.Jan 11 2021, 3:31 PM

Thanks for the review! Committed with your suggestions in 5ccff5aaa68ab789834c4463ce05b05e57593b34.