summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-01-10 23:28:43 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-01-10 23:28:43 +0000
commitcc7f008b850b301910132f94224dc02e32418f67 (patch)
tree6eab8a91a1f29f66a2097d7e4e2380e3936a7146 /clang/lib/CodeGen
parent098d7b76b0105f413df9e748a42a35fdc09733c0 (diff)
downloadbcm5719-llvm-cc7f008b850b301910132f94224dc02e32418f67.tar.gz
bcm5719-llvm-cc7f008b850b301910132f94224dc02e32418f67.zip
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 llvm-svn: 172144
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 7a604013b79..c5f94726e6f 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/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<CXXConstructExpr>(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);
OpenPOWER on IntegriCloud