diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2014-01-17 07:33:47 +0000 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2014-01-17 07:33:47 +0000 |
commit | c26905fb57d33edf623a5708090fb6f4a7988d57 (patch) | |
tree | e769782b0e5fb7dc97f2447a26e0bf486c7e924f /lib/Sema | |
parent | a93d8a5d2c31d36239588b0427fccbd5fc277a33 (diff) |
Revert r199416, "MS ABI: Improve selection of an inheritance model"
It broke tests for targeting x86_64-pc-win32:
Clang Tools :: clang-modernize/LoopConvert/array.cpp
Clang :: CodeGenCXX/2010-05-10-Var-DbgInfo.cpp
Clang :: CodeGenCXX/member-call-parens.cpp
Clang :: CodeGenCXX/ptr-to-datamember.cpp
Clang :: SemaTemplate/instantiate-function-1.cpp
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199475 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaCast.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 41 |
2 files changed, 29 insertions, 20 deletions
diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index 499e8b18be..63cb15db52 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -21,7 +21,6 @@ #include "clang/AST/ExprObjC.h" #include "clang/AST/RecordLayout.h" #include "clang/Basic/PartialDiagnostic.h" -#include "clang/Basic/TargetInfo.h" #include "clang/Sema/Initialization.h" #include "llvm/ADT/SmallVector.h" #include <set> @@ -1780,13 +1779,6 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, return TC_Failed; } - if (Self.Context.getTargetInfo().getCXXABI().isMicrosoft()) { - // We need to determine the inheritance model that the class will use if - // haven't yet. - Self.RequireCompleteType(OpRange.getBegin(), SrcType, 0); - Self.RequireCompleteType(OpRange.getBegin(), DestType, 0); - } - // Don't allow casting between member pointers of different sizes. if (Self.Context.getTypeSize(DestMemPtr) != Self.Context.getTypeSize(SrcMemPtr)) { diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 30edc48dd5..bc674d53d7 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -1753,6 +1753,35 @@ QualType Sema::BuildMemberPointerType(QualType T, QualType Class, return QualType(); } + // C++ allows the class type in a member pointer to be an incomplete type. + // In the Microsoft ABI, the size of the member pointer can vary + // according to the class type, which means that we really need a + // complete type if possible, which means we need to instantiate templates. + // + // If template instantiation fails or the type is just incomplete, we have to + // add an extra slot to the member pointer. Yes, this does cause problems + // when passing pointers between TUs that disagree about the size. + if (Context.getTargetInfo().getCXXABI().isMicrosoft()) { + CXXRecordDecl *RD = Class->getAsCXXRecordDecl(); + if (RD && !RD->hasAttr<MSInheritanceAttr>()) { + // Lock in the inheritance model on the first use of a member pointer. + // Otherwise we may disagree about the size at different points in the TU. + // FIXME: MSVC picks a model on the first use that needs to know the size, + // rather than on the first mention of the type, e.g. typedefs. + if (RequireCompleteType(Loc, Class, 0) && !RD->isBeingDefined()) { + // We know it doesn't have an attribute and it's incomplete, so use the + // unspecified inheritance model. If we're in the record body, we can + // figure out the inheritance model. + for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(), + E = RD->redecls_end(); I != E; ++I) { + I->addAttr(::new (Context) MSInheritanceAttr(RD->getSourceRange(), + Context, + MSInheritanceAttr::UnspecifiedSpellingIndex)); + } + } + } + } + // Adjust the default free function calling convention to the default method // calling convention. if (T->isFunctionType()) @@ -5067,18 +5096,6 @@ bool Sema::RequireCompleteTypeImpl(SourceLocation Loc, QualType T, } } - // We lock in the inheritance model once somebody has asked us to ensure - // that a pointer-to-member type is complete. - if (Context.getTargetInfo().getCXXABI().isMicrosoft()) { - if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>()) { - if (!MPTy->getClass()->isDependentType()) { - RequireCompleteType(Loc, QualType(MPTy->getClass(), 0), 0); - - MPTy->getMostRecentCXXRecordDecl()->setMSInheritanceModel(); - } - } - } - return false; } |