@@ -1531,34 +1531,21 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
1531
1531
std::optional<PrimType> ElemT = S.getContext ().classify (ElemType);
1532
1532
DynamicAllocator &Allocator = S.getAllocator ();
1533
1533
if (ElemT) {
1534
- if (IsArray) {
1535
- Block *B = Allocator.allocate (NewCall, *ElemT, NumElems.getZExtValue (),
1536
- S.Ctx .getEvalID (),
1537
- DynamicAllocator::Form::Operator);
1538
- assert (B);
1539
- S.Stk .push <Pointer>(Pointer (B).atIndex (0 ));
1540
- return true ;
1541
- }
1542
-
1543
- const Descriptor *Desc = S.P .createDescriptor (
1544
- NewCall, *ElemT, ElemType.getTypePtr (), Descriptor::InlineDescMD,
1545
- /* IsConst=*/ false , /* IsTemporary=*/ false ,
1546
- /* IsMutable=*/ false );
1547
- Block *B = Allocator.allocate (Desc, S.getContext ().getEvalID (),
1548
- DynamicAllocator::Form::Operator);
1534
+ Block *B =
1535
+ Allocator.allocate (NewCall, *ElemT, NumElems.getZExtValue (),
1536
+ S.Ctx .getEvalID (), DynamicAllocator::Form::Operator);
1549
1537
assert (B);
1550
-
1551
- S.Stk .push <Pointer>(B);
1538
+ S.Stk .push <Pointer>(Pointer (B).atIndex (0 ));
1552
1539
return true ;
1553
1540
}
1554
1541
1555
1542
assert (!ElemT);
1556
- // Structs etc.
1557
- const Descriptor *Desc =
1558
- S.P .createDescriptor (NewCall, ElemType.getTypePtr (),
1559
- IsArray ? std::nullopt : Descriptor::InlineDescMD);
1560
1543
1544
+ // Composite arrays
1561
1545
if (IsArray) {
1546
+ const Descriptor *Desc =
1547
+ S.P .createDescriptor (NewCall, ElemType.getTypePtr (),
1548
+ IsArray ? std::nullopt : Descriptor::InlineDescMD);
1562
1549
Block *B =
1563
1550
Allocator.allocate (Desc, NumElems.getZExtValue (), S.Ctx .getEvalID (),
1564
1551
DynamicAllocator::Form::Operator);
@@ -1567,10 +1554,17 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
1567
1554
return true ;
1568
1555
}
1569
1556
1557
+ // Records. Still allocate them as single-element arrays.
1558
+ QualType AllocType = S.getASTContext ().getConstantArrayType (
1559
+ ElemType, NumElems, nullptr , ArraySizeModifier::Normal, 0 );
1560
+
1561
+ const Descriptor *Desc =
1562
+ S.P .createDescriptor (NewCall, AllocType.getTypePtr (),
1563
+ IsArray ? std::nullopt : Descriptor::InlineDescMD);
1570
1564
Block *B = Allocator.allocate (Desc, S.getContext ().getEvalID (),
1571
1565
DynamicAllocator::Form::Operator);
1572
1566
assert (B);
1573
- S.Stk .push <Pointer>(B );
1567
+ S.Stk .push <Pointer>(Pointer (B). atIndex ( 0 ) );
1574
1568
return true ;
1575
1569
}
1576
1570
0 commit comments