[cfe-commits] r80701 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/destructors.cpp
Anders Carlsson
andersca at mac.com
Tue Sep 1 11:33:46 PDT 2009
Author: andersca
Date: Tue Sep 1 13:33:46 2009
New Revision: 80701
URL: http://llvm.org/viewvc/llvm-project?rev=80701&view=rev
Log:
We can generate constructors/destructors with base classes and non-trivial fields just fine now.
Added:
cfe/trunk/test/CodeGenCXX/destructors.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=80701&r1=80700&r2=80701&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Sep 1 13:33:46 2009
@@ -719,28 +719,7 @@
EmitBlock(DeleteEnd);
}
-static bool canGenerateCXXstructor(const CXXRecordDecl *RD,
- ASTContext &Context) {
- // The class has base classes - we don't support that right now.
- if (RD->getNumBases() > 0)
- return false;
-
- for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
- I != E; ++I) {
- // We don't support ctors for fields that aren't POD.
- if (!I->getType()->isPODType())
- return false;
- }
-
- return true;
-}
-
void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
- if (!canGenerateCXXstructor(D->getParent(), getContext())) {
- ErrorUnsupported(D, "C++ constructor", true);
- return;
- }
-
EmitGlobal(GlobalDecl(D, Ctor_Complete));
EmitGlobal(GlobalDecl(D, Ctor_Base));
}
@@ -778,11 +757,6 @@
}
void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) {
- if (!canGenerateCXXstructor(D->getParent(), getContext())) {
- ErrorUnsupported(D, "C++ destructor", true);
- return;
- }
-
EmitCXXDestructor(D, Dtor_Complete);
EmitCXXDestructor(D, Dtor_Base);
}
@@ -1613,6 +1587,7 @@
/// EmitCtorPrologue - This routine generates necessary code to initialize
/// base classes and non-static data members belonging to this constructor.
+/// FIXME: This needs to take a CXXCtorType.
void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) {
const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(CD->getDeclContext());
// FIXME: Add vbase initialization
@@ -1766,6 +1741,7 @@
/// EmitDtorEpilogue - Emit all code that comes at the end of class's
/// destructor. This is to call destructors on members and base classes
/// in reverse order of their construction.
+/// FIXME: This needs to take a CXXDtorType.
void CodeGenFunction::EmitDtorEpilogue(const CXXDestructorDecl *DD) {
const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(DD->getDeclContext());
assert(!ClassDecl->isPolymorphic() &&
Added: cfe/trunk/test/CodeGenCXX/destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=80701&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Tue Sep 1 13:33:46 2009
@@ -0,0 +1,22 @@
+// RUN: clang-cc %s -emit-llvm -o -
+struct A {
+ int a;
+
+ ~A();
+};
+
+// Base with non-trivial destructor
+struct B : A {
+ ~B();
+};
+
+B::~B() { }
+
+// Field with non-trivial destructor
+struct C {
+ A a;
+
+ ~C();
+};
+
+C::~C() { }
\ No newline at end of file
More information about the cfe-commits
mailing list