From: David Majnemer Date: Thu, 10 Sep 2015 07:20:05 +0000 (+0000) Subject: [MS ABI] Select a pointer to member representation more often X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bde095a7a76a2e76167f10a1f754257baa27a038;p=clang [MS ABI] Select a pointer to member representation more often Given a reference to a pointer to member whose class's inheritance model is unspecified, make sure we come up with an inheritance model in plausible places. One place we were missing involved LValue to RValue conversion, another involved unary type traits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247248 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index bfb98413a8..d55ac5ee83 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -677,6 +677,10 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) { if (T.hasQualifiers()) T = T.getUnqualifiedType(); + if (T->isMemberPointerType() && + Context.getTargetInfo().getCXXABI().isMicrosoft()) + RequireCompleteType(E->getExprLoc(), T, 0); + UpdateMarkingForLValueToRValue(E); // Loading a __weak object implicitly retains the value, so we need a cleanup to diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index a48e634c3c..e52aca1486 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4507,6 +4507,8 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &LHS, ExprResult &RHS, << OpSpelling << RHSType << RHS.get()->getSourceRange(); return QualType(); } + //if (Context.getTargetInfo().getCXXABI().isMicrosoft()) + // RequireCompleteType(Loc, QualType(MemPtr, 0), 0); QualType Class(MemPtr->getClass(), 0); diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 6b7a49dc33..63e69d3281 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -6253,9 +6253,13 @@ bool Sema::RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser){ QualType T = E->getType(); // Fast path the case where the type is already complete. - if (!T->isIncompleteType()) + if (!T->isIncompleteType()) { + if (T->isMemberPointerType() && + Context.getTargetInfo().getCXXABI().isMicrosoft()) + RequireCompleteType(E->getExprLoc(), T, 0); // FIXME: The definition might not be visible. return false; + } // Incomplete array types may be completed by the initializer attached to // their definitions. For static data members of class templates and for diff --git a/test/CodeGenCXX/microsoft-abi-member-pointers.cpp b/test/CodeGenCXX/microsoft-abi-member-pointers.cpp index 25d7c7702d..5d120700c8 100644 --- a/test/CodeGenCXX/microsoft-abi-member-pointers.cpp +++ b/test/CodeGenCXX/microsoft-abi-member-pointers.cpp @@ -752,3 +752,19 @@ void f(int S::*&p) {} // CHECK-LABEL: define void @"\01?f@PR24703@@YAXAAPQS@1@H@Z"( } +namespace ReferenceToMPTWithIncompleteClass { +struct S; +struct J; +struct K; +extern K *k; + +// CHECK-LABEL: @"\01?f@ReferenceToMPTWithIncompleteClass@@YAIAAPQS@1@H@Z"( +// CHECK: ret i32 12 +unsigned f(int S::*&p) { return sizeof p; } + +// CHECK-LABEL: @"\01?g@ReferenceToMPTWithIncompleteClass@@YA_NAAPQJ@1@H0@Z"( +bool g(int J::*&p, int J::*&q) { return p == q; } + +// CHECK-LABEL: @"\01?h@ReferenceToMPTWithIncompleteClass@@YAHAAPQK@1@H@Z"( +int h(int K::*&p) { return k->*p; } +}