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
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 7655f47..4f0d9a0 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -178,6 +178,11 @@
   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 @@
   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);