From c2316db5decd9cb7f8768ca67fad41fd8cffc110 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 10 Jan 2013 23:28:43 +0000 Subject: c++ IRGen. In trivial cases that object is going into static storage and thus is implicitly zero-initialized, no need to do C++11 memory model. This patch unconditionally detects such condition and zeroinitializer's the variable. Patch has been commented on and OKed by Doug off-line. // rdar://12897704 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172144 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 7a604013b7..c5f94726e6 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1006,6 +1006,23 @@ public: llvm::Constant *CodeGenModule::EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF) { + // Make a quick check if variable can be default NULL initialized + // and avoid going through rest of code which may do, for c++11, + // initialization of memory to all NULLs. + if (!D.hasLocalStorage()) { + QualType Ty = D.getType(); + if (Ty->isArrayType()) + Ty = Context.getBaseElementType(Ty); + if (Ty->isRecordType()) + if (const CXXConstructExpr *E = + dyn_cast_or_null(D.getInit())) { + const CXXConstructorDecl *CD = E->getConstructor(); + if (CD->isTrivial() && CD->isDefaultConstructor() && + Ty->getAsCXXRecordDecl()->hasTrivialDestructor()) + return EmitNullConstant(D.getType()); + } + } + if (const APValue *Value = D.evaluateValue()) return EmitConstantValueForMemory(*Value, D.getType(), CGF); -- cgit v1.2.3-18-g5258