@@ -429,6 +429,7 @@ fn T_tydesc(type_names tn) -> TypeRef {
429
429
}
430
430
431
431
fn T_array ( TypeRef t, uint n) -> TypeRef {
432
+ assert ( n != 0 u) ;
432
433
ret llvm. LLVMArrayType ( t, n) ;
433
434
}
434
435
@@ -437,7 +438,7 @@ fn T_vec(TypeRef t) -> TypeRef {
437
438
T_int ( ) , // Alloc
438
439
T_int ( ) , // Fill
439
440
T_int ( ) , // Pad
440
- T_array ( t, 0 u ) // Body elements
441
+ T_array ( t, 1 u ) // Body elements
441
442
) ) ;
442
443
}
443
444
@@ -540,7 +541,14 @@ fn T_tag(type_names tn, uint size) -> TypeRef {
540
541
if ( tn. name_has_type ( s) ) {
541
542
ret tn. get_type ( s) ;
542
543
}
543
- auto t = T_struct ( vec ( T_int ( ) , T_array ( T_i8 ( ) , size) ) ) ;
544
+
545
+ auto t;
546
+ if ( size == 0 u) {
547
+ t = T_struct ( vec ( T_int ( ) ) ) ;
548
+ } else {
549
+ t = T_struct ( vec ( T_int ( ) , T_array ( T_i8 ( ) , size) ) ) ;
550
+ }
551
+
544
552
tn. associate ( s, t) ;
545
553
ret t;
546
554
}
@@ -1592,16 +1600,28 @@ fn linearize_ty_params(@block_ctxt cx, ty.t t) ->
1592
1600
}
1593
1601
1594
1602
fn trans_stack_local_derived_tydesc( @block_ctxt cx, ValueRef llsz,
1595
- ValueRef llalign, ValueRef llroottydesc, ValueRef llparamtydescs )
1596
- -> result {
1603
+ ValueRef llalign, ValueRef llroottydesc,
1604
+ Option . t [ ValueRef ] llparamtydescs ) -> result {
1597
1605
auto llmyroottydesc = alloca( cx, T_tydesc ( cx. fcx. lcx. ccx. tn) ) ;
1598
1606
1599
1607
// By convention, desc 0 is the root descriptor.
1600
1608
llroottydesc = cx. build. Load ( llroottydesc) ;
1601
1609
cx. build. Store ( llroottydesc, llmyroottydesc) ;
1602
1610
1603
1611
// Store a pointer to the rest of the descriptors.
1604
- auto llfirstparam = cx. build. GEP ( llparamtydescs, vec( C_int( 0 ) , C_int ( 0 ) ) ) ;
1612
+ auto llrootfirstparam = cx. build. GEP ( llmyroottydesc,
1613
+ vec( C_int( 0 ) , C_int ( 0 ) ) ) ;
1614
+
1615
+ auto llfirstparam;
1616
+ alt ( llparamtydescs) {
1617
+ case ( none[ ValueRef ] ) {
1618
+ llfirstparam = C_null ( val_ty( llrootfirstparam) ) ;
1619
+ }
1620
+ case ( some[ ValueRef ] ( ?llparamtydescs) ) {
1621
+ llfirstparam = cx. build. GEP ( llparamtydescs,
1622
+ vec( C_int ( 0 ) , C_int ( 0 ) ) ) ;
1623
+ }
1624
+ }
1605
1625
cx. build. Store ( llfirstparam,
1606
1626
cx. build. GEP ( llmyroottydesc, vec( C_int ( 0 ) , C_int ( 0 ) ) ) ) ;
1607
1627
@@ -1650,18 +1670,26 @@ fn mk_derived_tydesc(@block_ctxt cx, ty.t t, bool escapes) -> result {
1650
1670
C_int ( ( 1 u + n_params) as int) ,
1651
1671
vp2i( bcx, tydescs) ) , true) ;
1652
1672
} else {
1653
- auto llparamtydescs = alloca( cx,
1654
- T_array ( T_ptr ( T_tydesc ( cx. fcx. lcx. ccx. tn) ) , n_params) ) ;
1673
+ auto llparamtydescs_opt;
1674
+ if ( n_params == 0 u) {
1675
+ llparamtydescs_opt = none[ ValueRef ] ;
1676
+ } else {
1677
+ auto llparamtydescs = alloca( cx,
1678
+ T_array ( T_ptr ( T_tydesc ( cx. fcx. lcx. ccx. tn) ) , n_params) ) ;
1655
1679
1656
- auto i = 0 ;
1657
- for ( ValueRef td in tys. _1) {
1658
- auto tdp = cx. build. GEP ( llparamtydescs, vec( C_int ( 0 ) , C_int ( i) ) ) ;
1659
- cx. build. Store ( td, tdp) ;
1660
- i += 1 ;
1680
+ auto i = 0 ;
1681
+ for ( ValueRef td in tys. _1 ) {
1682
+ auto tdp = cx. build . GEP ( llparamtydescs,
1683
+ vec ( C_int ( 0 ) , C_int ( i) ) ) ;
1684
+ cx. build . Store ( td, tdp) ;
1685
+ i += 1 ;
1686
+ }
1687
+
1688
+ llparamtydescs_opt = some[ ValueRef ] ( llparamtydescs) ;
1661
1689
}
1662
1690
1663
1691
v = trans_stack_local_derived_tydesc ( bcx, sz. val , align. val , root,
1664
- llparamtydescs ) ;
1692
+ llparamtydescs_opt ) ;
1665
1693
}
1666
1694
1667
1695
ret res ( v. bcx , vi2p ( v. bcx , v. val , T_ptr ( T_tydesc ( cx. fcx . lcx . ccx . tn ) ) ) ) ;
@@ -4269,7 +4297,7 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
4269
4297
auto body = next_cx. build. GEP ( v, vec( C_int ( 0 ) , C_int ( abi. vec_elt_data) ) ) ;
4270
4298
auto elt;
4271
4299
if ( ty. type_has_dynamic_size( cx. fcx. lcx. ccx. tcx, unit_ty) ) {
4272
- body = next_cx. build. PointerCast ( body, T_ptr ( T_array ( T_i8 ( ) , 0 u ) ) ) ;
4300
+ body = next_cx. build. PointerCast ( body, T_ptr ( T_array ( T_i8 ( ) , 1 u ) ) ) ;
4273
4301
elt = next_cx. build. GEP ( body, vec( C_int ( 0 ) , scaled_ix) ) ;
4274
4302
} else {
4275
4303
elt = next_cx. build. GEP ( body, vec( C_int ( 0 ) , ix_val) ) ;
0 commit comments