Corrections to r184205 ('this'-return optimization) due to the wrong version of the patch being committed originally.

1) Removed useless return value of CGCXXABI::EmitConstructorCall and CGCXXABI::EmitVirtualDestructorCall and implementations
2) Corrected last portion of CodeGenCXX/constructor-destructor-return-this to correctly test for non-'this'-return of virtual destructor calls

llvm-svn: 184330
This commit is contained in:
Stephen Lin 2013-06-19 18:10:35 +00:00
parent c0607ed68b
commit c467c873e6
6 changed files with 79 additions and 94 deletions

View File

@ -259,22 +259,20 @@ public:
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
/// Emit the constructor call. Return the function that is called.
virtual RValue EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D,
CXXCtorType Type,
bool ForVirtualBase, bool Delegating,
ReturnValueSlot ReturnValue,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd) = 0;
virtual void EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D,
CXXCtorType Type,
bool ForVirtualBase, bool Delegating,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd) = 0;
/// Emit the ABI-specific virtual destructor call.
virtual RValue EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
ReturnValueSlot ReturnValue,
llvm::Value *This) = 0;
virtual void EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
llvm::Value *This) = 0;
/// Emit any tables needed to implement virtual inheritance. For Itanium,
/// this emits virtual table tables. For the MSVC++ ABI, this emits virtual

View File

@ -1662,9 +1662,8 @@ CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
}
// Non-trivial constructors are handled in an ABI-specific manner.
CGM.getCXXABI().EmitConstructorCall(*this, D, Type,
ForVirtualBase, Delegating,
ReturnValueSlot(), This, ArgBeg, ArgEnd);
CGM.getCXXABI().EmitConstructorCall(*this, D, Type, ForVirtualBase,
Delegating, This, ArgBeg, ArgEnd);
}
void

View File

@ -280,16 +280,15 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE,
// We also don't emit a virtual call if the base expression has a record type
// because then we know what the type is.
bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod;
llvm::Value *Callee;
if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(MD)) {
assert(CE->arg_begin() == CE->arg_end() &&
"Destructor shouldn't have explicit parameters");
assert(ReturnValue.isNull() && "Destructor shouldn't have return value");
if (UseVirtualCall) {
assert(CE->arg_begin() == CE->arg_end() &&
"Virtual destructor shouldn't have explicit parameters");
return CGM.getCXXABI().EmitVirtualDestructorCall(*this, Dtor,
Dtor_Complete,
CE->getExprLoc(),
ReturnValue, This);
CGM.getCXXABI().EmitVirtualDestructorCall(*this, Dtor, Dtor_Complete,
CE->getExprLoc(), This);
} else {
if (getLangOpts().AppleKext &&
MD->isVirtual() &&
@ -302,12 +301,16 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE,
cast<CXXDestructorDecl>(DevirtualizedMethod);
Callee = CGM.GetAddrOfFunction(GlobalDecl(DDtor, Dtor_Complete), Ty);
}
EmitCXXMemberCall(MD, CE->getExprLoc(), Callee, ReturnValue, This,
/*ImplicitParam=*/0, QualType(), 0, 0);
}
} else if (const CXXConstructorDecl *Ctor =
dyn_cast<CXXConstructorDecl>(MD)) {
return RValue::get(0);
}
if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(MD)) {
Callee = CGM.GetAddrOfFunction(GlobalDecl(Ctor, Ctor_Complete), Ty);
} else if (UseVirtualCall) {
Callee = BuildVirtualCall(MD, This, Ty);
Callee = BuildVirtualCall(MD, This, Ty);
} else {
if (getLangOpts().AppleKext &&
MD->isVirtual() &&
@ -1413,8 +1416,7 @@ static void EmitObjectDelete(CodeGenFunction &CGF,
// FIXME: Provide a source location here.
CXXDtorType DtorType = UseGlobalDelete ? Dtor_Complete : Dtor_Deleting;
CGF.CGM.getCXXABI().EmitVirtualDestructorCall(CGF, Dtor, DtorType,
SourceLocation(),
ReturnValueSlot(), Ptr);
SourceLocation(), Ptr);
if (UseGlobalDelete) {
CGF.PopCleanupBlock();

View File

@ -119,21 +119,17 @@ public:
void EmitInstanceFunctionProlog(CodeGenFunction &CGF);
RValue EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D,
CXXCtorType Type,
bool ForVirtualBase, bool Delegating,
ReturnValueSlot ReturnValue,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd);
void EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D, CXXCtorType Type,
bool ForVirtualBase, bool Delegating,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd);
RValue EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
ReturnValueSlot ReturnValue,
llvm::Value *This);
void EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType, SourceLocation CallLoc,
llvm::Value *This);
void EmitVirtualInheritanceTables(llvm::GlobalVariable::LinkageTypes Linkage,
const CXXRecordDecl *RD);
@ -809,11 +805,10 @@ void ItaniumCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
CGF.Builder.CreateStore(getThisValue(CGF), CGF.ReturnValue);
}
RValue ItaniumCXXABI::EmitConstructorCall(CodeGenFunction &CGF,
void ItaniumCXXABI::EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D,
CXXCtorType Type,
bool ForVirtualBase, bool Delegating,
ReturnValueSlot ReturnValue,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd) {
@ -823,16 +818,15 @@ RValue ItaniumCXXABI::EmitConstructorCall(CodeGenFunction &CGF,
llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(D, Type);
// FIXME: Provide a source location here.
return CGF.EmitCXXMemberCall(D, SourceLocation(), Callee, ReturnValue,
This, VTT, VTTTy, ArgBeg, ArgEnd);
CGF.EmitCXXMemberCall(D, SourceLocation(), Callee, ReturnValueSlot(),
This, VTT, VTTTy, ArgBeg, ArgEnd);
}
RValue ItaniumCXXABI::EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
ReturnValueSlot ReturnValue,
llvm::Value *This) {
void ItaniumCXXABI::EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
llvm::Value *This) {
assert(DtorType == Dtor_Deleting || DtorType == Dtor_Complete);
const CGFunctionInfo *FInfo
@ -840,8 +834,8 @@ RValue ItaniumCXXABI::EmitVirtualDestructorCall(CodeGenFunction &CGF,
llvm::Type *Ty = CGF.CGM.getTypes().GetFunctionType(*FInfo);
llvm::Value *Callee = CGF.BuildVirtualCall(Dtor, DtorType, This, Ty);
return CGF.EmitCXXMemberCall(Dtor, CallLoc, Callee, ReturnValue, This,
/*ImplicitParam=*/0, QualType(), 0, 0);
CGF.EmitCXXMemberCall(Dtor, CallLoc, Callee, ReturnValueSlot(), This,
/*ImplicitParam=*/0, QualType(), 0, 0);
}
void ItaniumCXXABI::EmitVirtualInheritanceTables(

View File

@ -76,21 +76,17 @@ public:
void EmitInstanceFunctionProlog(CodeGenFunction &CGF);
RValue EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D,
CXXCtorType Type,
bool ForVirtualBase, bool Delegating,
ReturnValueSlot ReturnValue,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd);
RValue EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
ReturnValueSlot ReturnValue,
llvm::Value *This);
void EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D, CXXCtorType Type,
bool ForVirtualBase, bool Delegating,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd);
void EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType, SourceLocation CallLoc,
llvm::Value *This);
void EmitVirtualInheritanceTables(llvm::GlobalVariable::LinkageTypes Linkage,
const CXXRecordDecl *RD);
@ -459,13 +455,12 @@ void MicrosoftCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
}
}
RValue MicrosoftCXXABI::EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D,
CXXCtorType Type,
bool ForVirtualBase,
bool Delegating,
ReturnValueSlot ReturnValue,
llvm::Value *This,
void MicrosoftCXXABI::EmitConstructorCall(CodeGenFunction &CGF,
const CXXConstructorDecl *D,
CXXCtorType Type,
bool ForVirtualBase,
bool Delegating,
llvm::Value *This,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd) {
assert(Type == Ctor_Complete || Type == Ctor_Base);
@ -479,17 +474,15 @@ RValue MicrosoftCXXABI::EmitConstructorCall(CodeGenFunction &CGF,
}
// FIXME: Provide a source location here.
return CGF.EmitCXXMemberCall(D, SourceLocation(), Callee, ReturnValue,
This, ImplicitParam, ImplicitParamTy,
ArgBeg, ArgEnd);
CGF.EmitCXXMemberCall(D, SourceLocation(), Callee, ReturnValueSlot(), This,
ImplicitParam, ImplicitParamTy, ArgBeg, ArgEnd);
}
RValue MicrosoftCXXABI::EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
ReturnValueSlot ReturnValue,
llvm::Value *This) {
void MicrosoftCXXABI::EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
SourceLocation CallLoc,
llvm::Value *This) {
assert(DtorType == Dtor_Deleting || DtorType == Dtor_Complete);
// We have only one destructor in the vftable but can get both behaviors
@ -504,8 +497,8 @@ RValue MicrosoftCXXABI::EmitVirtualDestructorCall(CodeGenFunction &CGF,
= llvm::ConstantInt::get(llvm::IntegerType::getInt1Ty(CGF.getLLVMContext()),
DtorType == Dtor_Deleting);
return CGF.EmitCXXMemberCall(Dtor, CallLoc, Callee, ReturnValue, This,
ImplicitParam, Context.BoolTy, 0, 0);
CGF.EmitCXXMemberCall(Dtor, CallLoc, Callee, ReturnValueSlot(), This,
ImplicitParam, Context.BoolTy, 0, 0);
}
const VBTableVector &

View File

@ -100,21 +100,20 @@ public:
E* gete();
void test_destructor() {
E* e1 = new E();
const E& e1 = E();
E* e2 = gete();
e1->~E();
e2->~E();
}
// CHECKARM: define void @_Z15test_destructorv()
// CHECKARM: {{%.*}} = call %class.E* @_ZN1EC1Ev(%class.E*
// Verify that virtual calls to destructors are not marked with a 'returned'
// this parameter at the call site...
// CHECKARM: [[VFN:%.*]] = getelementptr inbounds %class.E* (%class.E*)**
// CHECKARM: [[THUNK:%.*]] = load %class.E* (%class.E*)** [[VFN]]
// CHECKARM: call %class.E* [[THUNK]](%class.E*
// CHECKARM: call %class.E* [[THUNK]](%class.E* %
// ...but static calls create declarations with 'returned' this
// CHECKARM: declare %class.E* @_ZN1EC1Ev(%class.E* returned)
// CHECKARM: {{%.*}} = call %class.E* @_ZN1ED1Ev(%class.E* %
// CHECKARM: declare %class.E* @_ZN1ED1Ev(%class.E* returned)