summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2014-01-17 07:33:47 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2014-01-17 07:33:47 +0000
commit5c486cf3f39c8a287ee9f341d324fc3160746ef0 (patch)
treee06b2667ef1ad30805aa811e7f0a12a4aa72bc64 /clang/lib/CodeGen
parenta49c2960c635b19373cc8e3714c6b29918b8f0b5 (diff)
downloadbcm5719-llvm-5c486cf3f39c8a287ee9f341d324fc3160746ef0.tar.gz
bcm5719-llvm-5c486cf3f39c8a287ee9f341d324fc3160746ef0.zip
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 llvm-svn: 199475
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/MicrosoftCXXABI.cpp89
1 files changed, 39 insertions, 50 deletions
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 875591d0df9..32f8ab2fb5d 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1322,29 +1322,25 @@ void MicrosoftCXXABI::EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
}
// Member pointer helpers.
-static bool hasVBPtrOffsetField(MSInheritanceAttr::Spelling Inheritance) {
- return Inheritance == MSInheritanceAttr::Keyword_unspecified_inheritance;
+static bool hasVBPtrOffsetField(MSInheritanceModel Inheritance) {
+ return Inheritance == MSIM_Unspecified;
}
static bool hasOnlyOneField(bool IsMemberFunction,
- MSInheritanceAttr::Spelling Inheritance) {
- if (IsMemberFunction)
- return Inheritance <= MSInheritanceAttr::Keyword_single_inheritance;
- return Inheritance <= MSInheritanceAttr::Keyword_multiple_inheritance;
+ MSInheritanceModel Inheritance) {
+ return Inheritance <= MSIM_SinglePolymorphic ||
+ (!IsMemberFunction && Inheritance <= MSIM_MultiplePolymorphic);
}
// Only member pointers to functions need a this adjustment, since it can be
// combined with the field offset for data pointers.
-static bool
-hasNonVirtualBaseAdjustmentField(bool IsMemberFunction,
- MSInheritanceAttr::Spelling Inheritance) {
- return IsMemberFunction &&
- Inheritance >= MSInheritanceAttr::Keyword_multiple_inheritance;
+static bool hasNonVirtualBaseAdjustmentField(bool IsMemberFunction,
+ MSInheritanceModel Inheritance) {
+ return (IsMemberFunction && Inheritance >= MSIM_Multiple);
}
-static bool
-hasVirtualBaseAdjustmentField(MSInheritanceAttr::Spelling Inheritance) {
- return Inheritance >= MSInheritanceAttr::Keyword_virtual_inheritance;
+static bool hasVirtualBaseAdjustmentField(MSInheritanceModel Inheritance) {
+ return Inheritance >= MSIM_Virtual;
}
// Use zero for the field offset of a null data member pointer if we can
@@ -1353,10 +1349,8 @@ hasVirtualBaseAdjustmentField(MSInheritanceAttr::Spelling Inheritance) {
// use zero for null. If there are multiple fields, we can use zero even if it
// is a valid field offset because null-ness testing will check the other
// fields.
-static bool nullFieldOffsetIsZero(const CXXRecordDecl *RD) {
- return RD->getMSInheritanceModel() >=
- MSInheritanceAttr::Keyword_virtual_inheritance ||
- (RD->hasDefinition() && RD->isPolymorphic());
+static bool nullFieldOffsetIsZero(MSInheritanceModel Inheritance) {
+ return Inheritance != MSIM_Multiple && Inheritance != MSIM_Single;
}
bool MicrosoftCXXABI::isZeroInitializable(const MemberPointerType *MPT) {
@@ -1368,16 +1362,16 @@ bool MicrosoftCXXABI::isZeroInitializable(const MemberPointerType *MPT) {
// The virtual base adjustment field is always -1 for null, so if we have one
// we can't zero initialize. The field offset is sometimes also -1 if 0 is a
// valid field offset.
- const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
- MSInheritanceAttr::Spelling Inheritance = RD->getMSInheritanceModel();
+ const CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
+ MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
return (!hasVirtualBaseAdjustmentField(Inheritance) &&
- nullFieldOffsetIsZero(RD));
+ nullFieldOffsetIsZero(Inheritance));
}
llvm::Type *
MicrosoftCXXABI::ConvertMemberPointerType(const MemberPointerType *MPT) {
- const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
- MSInheritanceAttr::Spelling Inheritance = RD->getMSInheritanceModel();
+ const CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
+ MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
llvm::SmallVector<llvm::Type *, 4> fields;
if (MPT->isMemberFunctionPointer())
fields.push_back(CGM.VoidPtrTy); // FunctionPointerOrVirtualThunk
@@ -1401,13 +1395,13 @@ void MicrosoftCXXABI::
GetNullMemberPointerFields(const MemberPointerType *MPT,
llvm::SmallVectorImpl<llvm::Constant *> &fields) {
assert(fields.empty());
- const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
- MSInheritanceAttr::Spelling Inheritance = RD->getMSInheritanceModel();
+ const CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
+ MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
if (MPT->isMemberFunctionPointer()) {
// FunctionPointerOrVirtualThunk
fields.push_back(llvm::Constant::getNullValue(CGM.VoidPtrTy));
} else {
- if (nullFieldOffsetIsZero(RD))
+ if (nullFieldOffsetIsZero(Inheritance))
fields.push_back(getZeroInt()); // FieldOffset
else
fields.push_back(getAllOnesInt()); // FieldOffset
@@ -1439,7 +1433,7 @@ MicrosoftCXXABI::EmitFullMemberPointer(llvm::Constant *FirstField,
const CXXRecordDecl *RD,
CharUnits NonVirtualBaseAdjustment)
{
- MSInheritanceAttr::Spelling Inheritance = RD->getMSInheritanceModel();
+ MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
// Single inheritance class member pointer are represented as scalars instead
// of aggregates.
@@ -1470,7 +1464,7 @@ MicrosoftCXXABI::EmitFullMemberPointer(llvm::Constant *FirstField,
llvm::Constant *
MicrosoftCXXABI::EmitMemberDataPointer(const MemberPointerType *MPT,
CharUnits offset) {
- const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
+ const CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
llvm::Constant *FirstField =
llvm::ConstantInt::get(CGM.IntTy, offset.getQuantity());
return EmitFullMemberPointer(FirstField, /*IsMemberFunction=*/false, RD,
@@ -1493,8 +1487,8 @@ llvm::Constant *MicrosoftCXXABI::EmitMemberPointer(const APValue &MP,
// FIXME PR15713: Support virtual inheritance paths.
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MPD))
- return BuildMemberPointer(MPT->getMostRecentCXXRecordDecl(), MD,
- ThisAdjustment);
+ return BuildMemberPointer(MPT->getClass()->getAsCXXRecordDecl(),
+ MD, ThisAdjustment);
CharUnits FieldOffset =
getContext().toCharUnitsFromBits(getContext().getFieldOffset(MPD));
@@ -1507,7 +1501,6 @@ MicrosoftCXXABI::BuildMemberPointer(const CXXRecordDecl *RD,
CharUnits NonVirtualBaseAdjustment) {
assert(MD->isInstance() && "Member function must not be static!");
MD = MD->getCanonicalDecl();
- RD = RD->getMostRecentDecl();
CodeGenTypes &Types = CGM.getTypes();
llvm::Constant *FirstField;
@@ -1585,8 +1578,8 @@ MicrosoftCXXABI::EmitMemberPointerComparison(CodeGenFunction &CGF,
// If this is a single field member pointer (single inheritance), this is a
// single icmp.
- const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
- MSInheritanceAttr::Spelling Inheritance = RD->getMSInheritanceModel();
+ const CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
+ MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
if (hasOnlyOneField(MPT->isMemberFunctionPointer(), Inheritance))
return Builder.CreateICmp(Eq, L, R);
@@ -1767,8 +1760,8 @@ MicrosoftCXXABI::EmitMemberDataPointerAddress(CodeGenFunction &CGF,
llvm::Type *PType =
CGF.ConvertTypeForMem(MPT->getPointeeType())->getPointerTo(AS);
CGBuilderTy &Builder = CGF.Builder;
- const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
- MSInheritanceAttr::Spelling Inheritance = RD->getMSInheritanceModel();
+ const CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
+ MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
// Extract the fields we need, regardless of model. We'll apply them if we
// have them.
@@ -1802,9 +1795,9 @@ MicrosoftCXXABI::EmitMemberDataPointerAddress(CodeGenFunction &CGF,
return Builder.CreateBitCast(Addr, PType);
}
-static MSInheritanceAttr::Spelling
+static MSInheritanceModel
getInheritanceFromMemptr(const MemberPointerType *MPT) {
- return MPT->getMostRecentCXXRecordDecl()->getMSInheritanceModel();
+ return MPT->getClass()->getAsCXXRecordDecl()->getMSInheritanceModel();
}
llvm::Value *
@@ -1824,17 +1817,15 @@ MicrosoftCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
const MemberPointerType *SrcTy =
E->getSubExpr()->getType()->castAs<MemberPointerType>();
const MemberPointerType *DstTy = E->getType()->castAs<MemberPointerType>();
+ MSInheritanceModel SrcInheritance = getInheritanceFromMemptr(SrcTy);
+ MSInheritanceModel DstInheritance = getInheritanceFromMemptr(DstTy);
bool IsFunc = SrcTy->isMemberFunctionPointer();
// If the classes use the same null representation, reinterpret_cast is a nop.
bool IsReinterpret = E->getCastKind() == CK_ReinterpretMemberPointer;
- if (IsReinterpret && IsFunc)
- return Src;
-
- CXXRecordDecl *SrcRD = SrcTy->getMostRecentCXXRecordDecl();
- CXXRecordDecl *DstRD = DstTy->getMostRecentCXXRecordDecl();
- if (IsReinterpret &&
- nullFieldOffsetIsZero(SrcRD) == nullFieldOffsetIsZero(DstRD))
+ if (IsReinterpret && (IsFunc ||
+ nullFieldOffsetIsZero(SrcInheritance) ==
+ nullFieldOffsetIsZero(DstInheritance)))
return Src;
CGBuilderTy &Builder = CGF.Builder;
@@ -1863,7 +1854,6 @@ MicrosoftCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
llvm::Value *NonVirtualBaseAdjustment = 0;
llvm::Value *VirtualBaseAdjustmentOffset = 0;
llvm::Value *VBPtrOffset = 0;
- MSInheritanceAttr::Spelling SrcInheritance = SrcRD->getMSInheritanceModel();
if (!hasOnlyOneField(IsFunc, SrcInheritance)) {
// We need to extract values.
unsigned I = 0;
@@ -1894,7 +1884,6 @@ MicrosoftCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
// FIXME PR15713: Support conversions through virtually derived classes.
// Recompose dst from the null struct and the adjusted fields from src.
- MSInheritanceAttr::Spelling DstInheritance = DstRD->getMSInheritanceModel();
llvm::Value *Dst;
if (hasOnlyOneField(IsFunc, DstInheritance)) {
Dst = FirstField;
@@ -1940,8 +1929,8 @@ MicrosoftCXXABI::EmitMemberPointerConversion(const CastExpr *E,
if (E->getCastKind() == CK_ReinterpretMemberPointer)
return Src;
- MSInheritanceAttr::Spelling SrcInheritance = getInheritanceFromMemptr(SrcTy);
- MSInheritanceAttr::Spelling DstInheritance = getInheritanceFromMemptr(DstTy);
+ MSInheritanceModel SrcInheritance = getInheritanceFromMemptr(SrcTy);
+ MSInheritanceModel DstInheritance = getInheritanceFromMemptr(DstTy);
// Decompose src.
llvm::Constant *FirstField = Src;
@@ -2002,13 +1991,13 @@ MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
assert(MPT->isMemberFunctionPointer());
const FunctionProtoType *FPT =
MPT->getPointeeType()->castAs<FunctionProtoType>();
- const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
+ const CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
llvm::FunctionType *FTy =
CGM.getTypes().GetFunctionType(
CGM.getTypes().arrangeCXXMethodType(RD, FPT));
CGBuilderTy &Builder = CGF.Builder;
- MSInheritanceAttr::Spelling Inheritance = RD->getMSInheritanceModel();
+ MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
// Extract the fields we need, regardless of model. We'll apply them if we
// have them.
OpenPOWER on IntegriCloud