diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-04 19:04:08 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-04 19:04:08 +0000 |
commit | 4fe95f99a2693f1145785ea5835ba6937e49c730 (patch) | |
tree | 0ee110356234d08d51bd2a76ded824e7043da003 /lib | |
parent | f79079565e15e6a328372076ac5583af16c8dbce (diff) |
Don't generate any code for an explicit call to a trivial destructor.
Now that parsing, semantic analysis, and (I think) code generation of
pseudo-destructor expressions and explicit destructor calls works,
update the example-dynarray.cpp test to destroy the objects it
allocates and update the test to actually compile + link.
The code seems correct, but the Clang-compiled version dies with a
malloc error. Time to debug!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81025 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 2 |
3 files changed, 10 insertions, 2 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 7655f47e44..4f0d9a0c5c 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -178,6 +178,11 @@ RValue CodeGenFunction::EmitCXXMemberCall(const CXXMethodDecl *MD, assert(MD->isInstance() && "Trying to emit a member call expr on a static method!"); + // A call to a trivial destructor requires no code generation. + if (const CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(MD)) + if (Destructor->isTrivial()) + return RValue::get(0); + const FunctionProtoType *FPT = MD->getType()->getAsFunctionProtoType(); CallArgList Args; @@ -218,6 +223,9 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE) { llvm::Value *Callee; if (MD->isVirtual() && !ME->hasQualifier()) Callee = BuildVirtualCall(MD, This, Ty); + else if (const CXXDestructorDecl *Destructor + = dyn_cast<CXXDestructorDecl>(MD)) + Callee = CGM.GetAddrOfFunction(GlobalDecl(Destructor, Dtor_Complete), Ty); else Callee = CGM.GetAddrOfFunction(GlobalDecl(MD), Ty); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 802df06b25..cde6e89d66 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -812,7 +812,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD, // If there was no specific requested type, just convert it now. if (!Ty) Ty = getTypes().ConvertType(GD.getDecl()->getType()); - return GetOrCreateLLVMFunction(getMangledName(GD.getDecl()), Ty, GD); + return GetOrCreateLLVMFunction(getMangledName(GD), Ty, GD); } /// CreateRuntimeFunction - Create a new runtime function with the specified diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index e5a4c6f81a..f8c59f4800 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2634,7 +2634,7 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, } void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation, - CXXDestructorDecl *Destructor) { + CXXDestructorDecl *Destructor) { assert((Destructor->isImplicit() && !Destructor->isUsed()) && "DefineImplicitDestructor - call it for implicit default dtor"); |