1010//
1111// ===----------------------------------------------------------------------===//
1212
13+ #include " clang/AST/CharUnits.h"
1314#include " clang/CIR/Dialect/IR/CIRAttrs.h"
1415#include " clang/CIR/MissingFeatures.h"
1516#include < CIRGenCXXABI.h>
@@ -876,6 +877,7 @@ void CIRGenFunction::emitNewArrayInitializer(
876877 unsigned InitListElements = 0 ;
877878
878879 const Expr *Init = E->getInitializer ();
880+ Address EndOfInit = Address::invalid ();
879881 QualType::DestructionKind DtorKind = ElementType.isDestructedType ();
880882 CleanupDeactivationScope deactivation (*this );
881883
@@ -898,7 +900,13 @@ void CIRGenFunction::emitNewArrayInitializer(
898900 // Subtract out the size of any elements we've already initialized.
899901 auto RemainingSize = AllocSizeWithoutCookie;
900902 if (InitListElements) {
901- llvm_unreachable (" NYI" );
903+ // We know this can't overflow; we check this when doing the allocation.
904+ unsigned InitializedSize =
905+ getContext ().getTypeSizeInChars (ElementType).getQuantity () *
906+ InitListElements;
907+ auto InitSizeOp =
908+ builder.getConstInt (Loc, RemainingSize.getType (), InitializedSize);
909+ RemainingSize = builder.createSub (RemainingSize, InitSizeOp);
902910 }
903911
904912 // Create the memset.
@@ -946,8 +954,24 @@ void CIRGenFunction::emitNewArrayInitializer(
946954 }
947955
948956 CharUnits StartAlign = CurPtr.getAlignment ();
957+ unsigned i = 0 ;
949958 for (const Expr *IE : InitExprs) {
950- llvm_unreachable (" NYI" );
959+ if (EndOfInit.isValid ()) {
960+ // This will involve DTor handling.
961+ llvm_unreachable (" NYI" );
962+ }
963+ // FIXME: If the last initializer is an incomplete initializer list for
964+ // an array, and we have an array filler, we can fold together the two
965+ // initialization loops.
966+ StoreAnyExprIntoOneUnit (*this , IE, IE->getType (), CurPtr,
967+ AggValueSlot::DoesNotOverlap);
968+ auto Loc = getLoc (IE->getExprLoc ());
969+ auto CastOp = builder.createPtrBitcast (CurPtr.getPointer (),
970+ convertTypeForMem (AllocType));
971+ auto OffsetOp = builder.getSignedInt (Loc, 1 , /* width=*/ 32 );
972+ auto DataPtr = builder.createPtrStride (Loc, CastOp, OffsetOp);
973+ CurPtr = Address (DataPtr, CurPtr.getType (),
974+ StartAlign.alignmentAtOffset ((++i) * ElementSize));
951975 }
952976
953977 // The remaining elements are filled with the array filler expression.
0 commit comments