[cfe-commits] r172144 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Jan 10 15:28:43 PST 2013
Author: fjahanian
Date: Thu Jan 10 17:28:43 2013
New Revision: 172144
URL: http://llvm.org/viewvc/llvm-project?rev=172144&view=rev
Log:
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
Added:
cfe/trunk/test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=172144&r1=172143&r2=172144&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu Jan 10 17:28:43 2013
@@ -1006,6 +1006,23 @@
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);
Added: cfe/trunk/test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp?rev=172144&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp Thu Jan 10 17:28:43 2013
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -S -emit-llvm -o %t.ll %s -triple x86_64-apple-darwin10
+// RUN: %clang_cc1 -std=c++11 -S -emit-llvm -o %t-c++11.ll %s -triple x86_64-apple-darwin10
+// RUN: diff %t.ll %t-c++11.ll
+
+// rdar://12897704
+
+struct sAFSearchPos {
+ unsigned char *pos;
+ unsigned char count;
+};
+
+static volatile struct sAFSearchPos testPositions;
+
+static volatile struct sAFSearchPos arrayPositions[100][10][5];
+
+int main() {
+ return testPositions.count + arrayPositions[10][4][3].count;
+}
More information about the cfe-commits
mailing list