This is an archive of the discontinued LLVM Phabricator instance.

Add support for TinyPtrVector<PointerIntPair<...> >
AbandonedPublic

Authored by atrick on Aug 2 2019, 5:00 PM.

Details

Reviewers
chandlerc
rsmith
Summary

PointerIntPair and PointerUnion already mostly support nesting pointer-like types, but support was incomplete. PointerUnion::isNull still assumed that a union member was a true C++ pointer type. The meaning of PointerUnion::isNull is that the nested pointer component is null regardless of any other spare bits recursively. To adhere to the original intention of this API and fully support nested pointer types, we PointerLikeTypesTraits needs a new isNull() static method.

Once we have PointerLikeTypesTraits::isNull(), it's easy to make TinyPtrVector generic over pointer-like values. We just call isNull instead of assuming that pointer-like things are convertible to bool

Note that we don't actually want all pointer-like things to be convertible to bool because that's ambiguous for PointerIntPair.

Diff Detail

Event Timeline

atrick created this revision.Aug 2 2019, 5:00 PM
atrick added a comment.EditedAug 2 2019, 6:58 PM

This breaks the clang build because there are a handful of PointerLikeTypeTraits specializations that specify higher alignment:

template<>
struct PointerLikeTypeTraits< ::clang::Type*> {
  static inline void *getAsVoidPointer(::clang::Type *P) { return P; }

  static inline ::clang::Type *getFromVoidPointer(void *P) {
    return static_cast< ::clang::Type*>(P);
  }

  enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
};
atrick abandoned this revision.Aug 2 2019, 7:25 PM

I'm abandoning this. Adding a member to PointerLikeTypeTraits is going to be a merge problem for some LLVM projects. I'm going back to the simpler way of converting to PtrToIntPair to an opaque pointers to check whether it can be an element in TinyPtrVector now that I've convinced myself that the simple way is still correct.