[PATCH] [ms-cxxabi] Implement member data pointers for non-dynamic classes
John McCall
rjmccall at apple.com
Wed Mar 20 19:57:13 PDT 2013
On Mar 20, 2013, at 3:59 PM, Reid Kleckner <rnk at google.com> wrote:
> CHANGE SINCE LAST DIFF
> http://llvm-reviews.chandlerc.com/D558?vs=1333&id=1338#toc
+ // It's a little silly for us to cache this.
+ llvm::IntegerType *getPtrDiffTy() {
It's actually CGM.PtrDiffTy, so there was never a good reason to cache it
separately.
+llvm::Constant *
+MicrosoftCXXABI::getNullMemberDataPointer(const MemberPointerType *MPT) {
+ assert(MPT->isMemberDataPointer());
+ llvm::Constant *Zero = llvm::ConstantInt::get(getPtrDiffTy(), 0);
+ llvm::Constant *AllOnes = llvm::Constant::getAllOnesValue(getPtrDiffTy());
+ const CXXRecordDecl *RD =
+ cast<CXXRecordDecl>(MPT->getClass()->getAs<RecordType>()->getDecl());
MPT->getClass()->getAsCXXRecordDecl()
+ if (RD->getNumVBases() == 0) {
I don't think you can safely call this on a forward-declaration.
Why don't you make helper functions to create the all-ones and all-zero
ptrdiff_t values? That would make this code much more succinct.
+ // FIXME: Emit a pair of {vbtable offset, field offset} when we know vbtable
+ // layout.
+ return GetBogusMemberPointer(QualType(MPT, 0));
I don't think this ever actually comes up here. If it did, you'd need a
totally different interface anyway.
I believe vb-table offsets are only introduced when you convert across a
virtual base boundary.
+ // For member data pointers, this is just a check against -1 or 0.
+ if (MPT->isMemberDataPointer()) {
+ assert(MemPtr->getType() == getPtrDiffTy());
+ llvm::Constant *Val = getNullMemberDataPointer(MPT);
+ return Builder.CreateICmpNE(MemPtr, Val, "memptr.tobool");
+ }
You forgot the virtual inheritance case here.
+ if (MemPtr->getType() != getPtrDiffTy()) {
+ // If it's not a ptrdiff_t, then it's an aggregate.
+ ErrorUnsupportedABI(CGF, "non-scalar member pointers");
+ return llvm::Constant::getNullValue(PType);
+ }
+
Shouldn't this be pretty straightforward to implement? We may not know
how to lay out a vbtbl yet, so the conversion case will still elude us, but we
do know the offset of the vb-table and how to do an offsetted load out of it.
John.
More information about the cfe-commits
mailing list