[cfe-commits] r81025 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDeclCXX.cpp test/SemaTemplate/example-dynarray.cpp www/cxx_status.html

Douglas Gregor dgregor at apple.com
Fri Sep 4 12:04:08 PDT 2009


Author: dgregor
Date: Fri Sep  4 14:04:08 2009
New Revision: 81025

URL: http://llvm.org/viewvc/llvm-project?rev=81025&view=rev
Log:
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!


Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaTemplate/example-dynarray.cpp
    cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=81025&r1=81024&r2=81025&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Sep  4 14:04:08 2009
@@ -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);
   

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=81025&r1=81024&r2=81025&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Sep  4 14:04:08 2009
@@ -812,7 +812,7 @@
   // 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

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=81025&r1=81024&r2=81025&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Sep  4 14:04:08 2009
@@ -2634,7 +2634,7 @@
 }
 
 void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation,
-                                            CXXDestructorDecl *Destructor) {
+                                    CXXDestructorDecl *Destructor) {
   assert((Destructor->isImplicit() && !Destructor->isUsed()) &&
          "DefineImplicitDestructor - call it for implicit default dtor");
   

Modified: cfe/trunk/test/SemaTemplate/example-dynarray.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/example-dynarray.cpp?rev=81025&r1=81024&r2=81025&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/example-dynarray.cpp (original)
+++ cfe/trunk/test/SemaTemplate/example-dynarray.cpp Fri Sep  4 14:04:08 2009
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify %s
+// RUN: clang %s -o %t
 #include <stddef.h>
 #include <stdlib.h>
 #include <assert.h>
@@ -24,6 +24,9 @@
   }
   
   ~dynarray() {
+    for (unsigned I = 0, N = size(); I != N; ++I)
+      Start[I].~T();
+    
     free(Start);
   }
 
@@ -33,7 +36,9 @@
     for (unsigned I = 0, N = other.size(); I != N; ++I)
       new (NewStart + I) T(other[I]);
 
-    // FIXME: destroy everything in Start
+    for (unsigned I = 0, N = size(); I != N; ++I)
+      Start[I].~T();
+    
     free(Start);
     Start = NewStart;
     Last = End = NewStart + other.size();
@@ -46,8 +51,8 @@
   void push_back(const T& value);
   
   void pop_back() {
-    // FIXME: destruct old value
     --Last;
+    Last->~T();
   }
 
   T& operator[](unsigned Idx) {
@@ -99,7 +104,8 @@
     for (unsigned I = 0; I != Size; ++I)
       new (NewStart + I) T(Start[I]);
     
-    // FIXME: destruct old values
+    for (unsigned I = 0, N = size(); I != N; ++I)
+      Start[I].~T();
     free(Start);
     
     Start = NewStart;

Modified: cfe/trunk/www/cxx_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=81025&r1=81024&r2=81025&view=diff

==============================================================================
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Fri Sep  4 14:04:08 2009
@@ -574,9 +574,9 @@
 <tr>
   <td>    5.2.4 [expr.pseudo]</td>
   <td class="complete"></td>
-  <td class="medium"></td>
-  <td class="medium"></td>
-  <td></td>
+  <td class="complete"></td>
+  <td class="complete"></td>
+  <td class="complete"></td>
   <td></td>
 </tr>
 <tr>





More information about the cfe-commits mailing list