diff options
author | Anders Carlsson <andersca@mac.com> | 2009-12-10 00:16:00 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-12-10 00:16:00 +0000 |
commit | 5ec2e7ccb08b2a1598f12b2c6f59c6f31d035b5b (patch) | |
tree | cf6df4a2353a8a42a6a99602607285a41cc4be37 /lib/CodeGen/CGDeclCXX.cpp | |
parent | 68f7a2426227476bcfa33ada70b708c82419dfdc (diff) |
Add CGDeclCXX.cpp and move EmitCXXGlobalVarDeclInit there.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91006 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDeclCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGDeclCXX.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
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); + } + } + } +} + |