aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/CGCXX.cpp45
-rw-r--r--lib/CodeGen/CGDeclCXX.cpp62
-rw-r--r--lib/CodeGen/CMakeLists.txt1
3 files changed, 63 insertions, 45 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 7bffad49a7..d3ea2c7884 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -61,51 +61,6 @@ CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
Builder.CreateCall(AtExitFn, &Args[0], llvm::array_endof(Args));
}
-void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
- llvm::Constant *DeclPtr) {
- assert(D.hasGlobalStorage() &&
- "VarDecl must have global storage!");
-
- const Expr *Init = D.getInit();
- QualType T = D.getType();
- bool isVolatile = getContext().getCanonicalType(T).isVolatileQualified();
-
- if (T->isReferenceType()) {
- ErrorUnsupported(Init, "global variable that binds to a reference");
- } else if (!hasAggregateLLVMType(T)) {
- llvm::Value *V = EmitScalarExpr(Init);
- EmitStoreOfScalar(V, DeclPtr, isVolatile, T);
- } else if (T->isAnyComplexType()) {
- EmitComplexExprIntoAddr(Init, DeclPtr, isVolatile);
- } else {
- EmitAggExpr(Init, DeclPtr, isVolatile);
- // Avoid generating destructor(s) for initialized objects.
- if (!isa<CXXConstructExpr>(Init))
- return;
- const ConstantArrayType *Array = getContext().getAsConstantArrayType(T);
- if (Array)
- T = getContext().getBaseElementType(Array);
-
- if (const RecordType *RT = T->getAs<RecordType>()) {
- CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
- if (!RD->hasTrivialDestructor()) {
- llvm::Constant *DtorFn;
- if (Array) {
- DtorFn = CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(
- RD->getDestructor(getContext()),
- Array, DeclPtr);
- DeclPtr =
- llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
- }
- else
- DtorFn = CGM.GetAddrOfCXXDestructor(RD->getDestructor(getContext()),
- Dtor_Complete);
- EmitCXXGlobalDtorRegistration(DtorFn, DeclPtr);
- }
- }
- }
-}
-
void
CodeGenModule::EmitCXXGlobalInitFunc() {
if (CXXGlobalInits.empty())
diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp
new file mode 100644
index 0000000000..b048cf886e
--- /dev/null
+++ b/lib/CodeGen/CGDeclCXX.cpp
@@ -0,0 +1,62 @@
+//===--- CGDeclCXX.cpp - Emit LLVM Code for C++ declarations --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code dealing with code generation of C++ declarations
+//
+//===----------------------------------------------------------------------===//
+
+#include "CodeGenFunction.h"
+using namespace clang;
+using namespace CodeGen;
+
+void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
+ llvm::Constant *DeclPtr) {
+ assert(D.hasGlobalStorage() &&
+ "VarDecl must have global storage!");
+
+ const Expr *Init = D.getInit();
+ QualType T = D.getType();
+ bool isVolatile = getContext().getCanonicalType(T).isVolatileQualified();
+
+ if (T->isReferenceType()) {
+ ErrorUnsupported(Init, "global variable that binds to a reference");
+ } else if (!hasAggregateLLVMType(T)) {
+ llvm::Value *V = EmitScalarExpr(Init);
+ EmitStoreOfScalar(V, DeclPtr, isVolatile, T);
+ } else if (T->isAnyComplexType()) {
+ EmitComplexExprIntoAddr(Init, DeclPtr, isVolatile);
+ } else {
+ EmitAggExpr(Init, DeclPtr, isVolatile);
+ // Avoid generating destructor(s) for initialized objects.
+ if (!isa<CXXConstructExpr>(Init))
+ return;
+ const ConstantArrayType *Array = getContext().getAsConstantArrayType(T);
+ if (Array)
+ T = getContext().getBaseElementType(Array);
+
+ if (const RecordType *RT = T->getAs<RecordType>()) {
+ CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+ if (!RD->hasTrivialDestructor()) {
+ llvm::Constant *DtorFn;
+ if (Array) {
+ DtorFn = CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(
+ RD->getDestructor(getContext()),
+ Array, DeclPtr);
+ DeclPtr =
+ llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
+ }
+ else
+ DtorFn = CGM.GetAddrOfCXXDestructor(RD->getDestructor(getContext()),
+ Dtor_Complete);
+ EmitCXXGlobalDtorRegistration(DtorFn, DeclPtr);
+ }
+ }
+ }
+}
+
diff --git a/lib/CodeGen/CMakeLists.txt b/lib/CodeGen/CMakeLists.txt
index a1fb5ad745..3c26484740 100644
--- a/lib/CodeGen/CMakeLists.txt
+++ b/lib/CodeGen/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangCodeGen
CGCXX.cpp
CGDebugInfo.cpp
CGDecl.cpp
+ CGDeclCXX.cpp
CGException.cpp
CGExpr.cpp
CGExprAgg.cpp