10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " clang/AST/CharUnits.h"
13
14
#include " clang/CIR/Dialect/IR/CIRAttrs.h"
14
15
#include " clang/CIR/MissingFeatures.h"
15
16
#include < CIRGenCXXABI.h>
@@ -876,6 +877,7 @@ void CIRGenFunction::emitNewArrayInitializer(
876
877
unsigned InitListElements = 0 ;
877
878
878
879
const Expr *Init = E->getInitializer ();
880
+ Address EndOfInit = Address::invalid ();
879
881
QualType::DestructionKind DtorKind = ElementType.isDestructedType ();
880
882
CleanupDeactivationScope deactivation (*this );
881
883
@@ -898,7 +900,13 @@ void CIRGenFunction::emitNewArrayInitializer(
898
900
// Subtract out the size of any elements we've already initialized.
899
901
auto RemainingSize = AllocSizeWithoutCookie;
900
902
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);
902
910
}
903
911
904
912
// Create the memset.
@@ -946,8 +954,24 @@ void CIRGenFunction::emitNewArrayInitializer(
946
954
}
947
955
948
956
CharUnits StartAlign = CurPtr.getAlignment ();
957
+ unsigned i = 0 ;
949
958
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));
951
975
}
952
976
953
977
// The remaining elements are filled with the array filler expression.
0 commit comments