@@ -296,64 +296,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
296
296
void VisitCXXConstructExpr (const CXXConstructExpr *E);
297
297
void VisitCXXInheritedCtorInitExpr (const CXXInheritedCtorInitExpr *E);
298
298
void VisitLambdaExpr (LambdaExpr *E);
299
- void VisitCXXStdInitializerListExpr (CXXStdInitializerListExpr *E) {
300
- ASTContext &Ctx = CGF.getContext ();
301
- CIRGenFunction::SourceLocRAIIObject locRAIIObject{
302
- CGF, CGF.getLoc (E->getSourceRange ())};
303
- // Emit an array containing the elements. The array is externally
304
- // destructed if the std::initializer_list object is.
305
- LValue Array = CGF.emitLValue (E->getSubExpr ());
306
- assert (Array.isSimple () && " initializer_list array not a simple lvalue" );
307
- Address ArrayPtr = Array.getAddress ();
308
-
309
- const ConstantArrayType *ArrayType =
310
- Ctx.getAsConstantArrayType (E->getSubExpr ()->getType ());
311
- assert (ArrayType && " std::initializer_list constructed from non-array" );
312
-
313
- RecordDecl *Record = E->getType ()->castAs <RecordType>()->getDecl ();
314
- RecordDecl::field_iterator Field = Record->field_begin ();
315
- assert (Field != Record->field_end () &&
316
- Ctx.hasSameType (Field->getType ()->getPointeeType (),
317
- ArrayType->getElementType ()) &&
318
- " Expected std::initializer_list first field to be const E *" );
319
- // Start pointer.
320
- auto loc = CGF.getLoc (E->getSourceRange ());
321
- AggValueSlot Dest = EnsureSlot (loc, E->getType ());
322
- LValue DestLV = CGF.makeAddrLValue (Dest.getAddress (), E->getType ());
323
- LValue Start =
324
- CGF.emitLValueForFieldInitialization (DestLV, *Field, Field->getName ());
325
- mlir::Value ArrayStart = ArrayPtr.emitRawPointer ();
326
- CGF.emitStoreThroughLValue (RValue::get (ArrayStart), Start);
327
- ++Field;
328
- assert (Field != Record->field_end () &&
329
- " Expected std::initializer_list to have two fields" );
330
-
331
- auto Builder = CGF.getBuilder ();
332
-
333
- auto sizeOp = Builder.getConstInt (loc, ArrayType->getSize ());
334
-
335
- mlir::Value Size = sizeOp.getRes ();
336
- Builder.getUIntNTy (ArrayType->getSizeBitWidth ());
337
- LValue EndOrLength =
338
- CGF.emitLValueForFieldInitialization (DestLV, *Field, Field->getName ());
339
- if (Ctx.hasSameType (Field->getType (), Ctx.getSizeType ())) {
340
- // Length.
341
- CGF.emitStoreThroughLValue (RValue::get (Size), EndOrLength);
342
- } else {
343
- // End pointer.
344
- assert (Field->getType ()->isPointerType () &&
345
- Ctx.hasSameType (Field->getType ()->getPointeeType (),
346
- ArrayType->getElementType ()) &&
347
- " Expected std::initializer_list second field to be const E *" );
348
-
349
- auto ArrayEnd =
350
- Builder.getArrayElement (loc, loc, ArrayPtr.getPointer (),
351
- ArrayPtr.getElementType (), Size, false );
352
- CGF.emitStoreThroughLValue (RValue::get (ArrayEnd), EndOrLength);
353
- }
354
- assert (++Field == Record->field_end () &&
355
- " Expected std::initializer_list to only have two fields" );
356
- }
299
+ void VisitCXXStdInitializerListExpr (CXXStdInitializerListExpr *E);
357
300
358
301
void VisitExprWithCleanups (ExprWithCleanups *E);
359
302
void VisitCXXScalarValueInitExpr (CXXScalarValueInitExpr *E) {
@@ -954,6 +897,69 @@ void AggExprEmitter::VisitLambdaExpr(LambdaExpr *E) {
954
897
}
955
898
}
956
899
900
+ void AggExprEmitter::VisitCXXStdInitializerListExpr (
901
+ CXXStdInitializerListExpr *E) {
902
+ ASTContext &Ctx = CGF.getContext ();
903
+ CIRGenFunction::SourceLocRAIIObject locRAIIObject{
904
+ CGF, CGF.getLoc (E->getSourceRange ())};
905
+ // Emit an array containing the elements. The array is externally
906
+ // destructed if the std::initializer_list object is.
907
+ LValue Array = CGF.emitLValue (E->getSubExpr ());
908
+ assert (Array.isSimple () && " initializer_list array not a simple lvalue" );
909
+ Address ArrayPtr = Array.getAddress ();
910
+
911
+ const ConstantArrayType *ArrayType =
912
+ Ctx.getAsConstantArrayType (E->getSubExpr ()->getType ());
913
+ assert (ArrayType && " std::initializer_list constructed from non-array" );
914
+
915
+ RecordDecl *Record = E->getType ()->castAs <RecordType>()->getDecl ();
916
+ RecordDecl::field_iterator Field = Record->field_begin ();
917
+ assert (Field != Record->field_end () &&
918
+ Ctx.hasSameType (Field->getType ()->getPointeeType (),
919
+ ArrayType->getElementType ()) &&
920
+ " Expected std::initializer_list first field to be const E *" );
921
+ const FieldDecl *StartField = *Field;
922
+ ++Field;
923
+ assert (Field != Record->field_end () &&
924
+ " Expected std::initializer_list to have two fields" );
925
+ const FieldDecl *EndOrLengthField = *Field;
926
+ ++Field;
927
+ assert (Field == Record->field_end () &&
928
+ " Expected std::initializer_list to only have two fields" );
929
+
930
+ // Start pointer.
931
+ auto loc = CGF.getLoc (E->getSourceRange ());
932
+ AggValueSlot Dest = EnsureSlot (loc, E->getType ());
933
+ LValue DestLV = CGF.makeAddrLValue (Dest.getAddress (), E->getType ());
934
+ LValue Start = CGF.emitLValueForFieldInitialization (DestLV, StartField,
935
+ StartField->getName ());
936
+ mlir::Value ArrayStart = ArrayPtr.emitRawPointer ();
937
+ CGF.emitStoreThroughLValue (RValue::get (ArrayStart), Start);
938
+
939
+ auto Builder = CGF.getBuilder ();
940
+
941
+ auto sizeOp = Builder.getConstInt (loc, ArrayType->getSize ());
942
+
943
+ mlir::Value Size = sizeOp.getRes ();
944
+ LValue EndOrLength = CGF.emitLValueForFieldInitialization (
945
+ DestLV, EndOrLengthField, EndOrLengthField->getName ());
946
+ if (Ctx.hasSameType (EndOrLengthField->getType (), Ctx.getSizeType ())) {
947
+ // Length.
948
+ CGF.emitStoreThroughLValue (RValue::get (Size), EndOrLength);
949
+ } else {
950
+ // End pointer.
951
+ assert (EndOrLengthField->getType ()->isPointerType () &&
952
+ Ctx.hasSameType (EndOrLengthField->getType ()->getPointeeType (),
953
+ ArrayType->getElementType ()) &&
954
+ " Expected std::initializer_list second field to be const E *" );
955
+
956
+ auto ArrayEnd =
957
+ Builder.getArrayElement (loc, loc, ArrayPtr.getPointer (),
958
+ ArrayPtr.getElementType (), Size, false );
959
+ CGF.emitStoreThroughLValue (RValue::get (ArrayEnd), EndOrLength);
960
+ }
961
+ }
962
+
957
963
void AggExprEmitter::VisitCastExpr (CastExpr *E) {
958
964
if (const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
959
965
CGF.CGM .emitExplicitCastExprType (ECE, &CGF);
0 commit comments