summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprCXX.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-06-03 08:26:00 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-06-03 08:26:00 +0000
commit80fe8a6c2142df4718e2482a0562ee6142de1685 (patch)
tree9d6edb9d38af9d9163661f2a5b51c78392a678d2 /lib/CodeGen/CGExprCXX.cpp
parentea7885793bc604f566db6d1d99c845bfec6b8119 (diff)
downloadclang-80fe8a6c2142df4718e2482a0562ee6142de1685.tar.gz
clang-80fe8a6c2142df4718e2482a0562ee6142de1685.tar.bz2
clang-80fe8a6c2142df4718e2482a0562ee6142de1685.tar.xz
Implement DR990 and DR1070. Aggregate initialization initializes uninitialized
elements from {}, rather than value-initializing them. This permits calling an initializer-list constructor or constructing a std::initializer_list object. (It would also permit initializing a const reference or rvalue reference if that weren't explicitly prohibited by other rules.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210091 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprCXX.cpp')
-rw-r--r--lib/CodeGen/CGExprCXX.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index c6995d8a1b..762d8e2959 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -858,9 +858,21 @@ CodeGenFunction::EmitNewArrayInitializer(const CXXNewExpr *E,
return true;
};
+ // If all elements have already been initialized, skip any further
+ // initialization.
+ llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
+ if (ConstNum && ConstNum->getZExtValue() <= InitListElements) {
+ // If there was a Cleanup, deactivate it.
+ if (CleanupDominator)
+ DeactivateCleanupBlock(Cleanup, CleanupDominator);
+ return;
+ }
+
+ assert(Init && "have trailing elements to initialize but no initializer");
+
// If this is a constructor call, try to optimize it out, and failing that
// emit a single loop to initialize all remaining elements.
- if (const CXXConstructExpr *CCE = dyn_cast_or_null<CXXConstructExpr>(Init)){
+ if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) {
CXXConstructorDecl *Ctor = CCE->getConstructor();
if (Ctor->isTrivial()) {
// If new expression did not specify value-initialization, then there
@@ -891,7 +903,7 @@ CodeGenFunction::EmitNewArrayInitializer(const CXXNewExpr *E,
// If this is value-initialization, we can usually use memset.
ImplicitValueInitExpr IVIE(ElementType);
- if (Init && isa<ImplicitValueInitExpr>(Init)) {
+ if (isa<ImplicitValueInitExpr>(Init)) {
if (TryMemsetInitialization())
return;
@@ -906,15 +918,10 @@ CodeGenFunction::EmitNewArrayInitializer(const CXXNewExpr *E,
assert(getContext().hasSameUnqualifiedType(ElementType, Init->getType()) &&
"got wrong type of element to initialize");
- llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
-
- // If all elements have already been initialized, skip the whole loop.
- if (ConstNum && ConstNum->getZExtValue() <= InitListElements) {
- // If there was a Cleanup, deactivate it.
- if (CleanupDominator)
- DeactivateCleanupBlock(Cleanup, CleanupDominator);
- return;
- }
+ // If we have an empty initializer list, we can usually use memset.
+ if (auto *ILE = dyn_cast<InitListExpr>(Init))
+ if (ILE->getNumInits() == 0 && TryMemsetInitialization())
+ return;
// Create the loop blocks.
llvm::BasicBlock *EntryBB = Builder.GetInsertBlock();