@@ -429,6 +429,7 @@ fn T_tydesc(type_names tn) -> TypeRef {
429429}
430430
431431fn T_array ( TypeRef t, uint n) -> TypeRef {
432+ assert ( n != 0 u) ;
432433 ret llvm. LLVMArrayType ( t, n) ;
433434}
434435
@@ -437,7 +438,7 @@ fn T_vec(TypeRef t) -> TypeRef {
437438 T_int ( ) , // Alloc
438439 T_int ( ) , // Fill
439440 T_int ( ) , // Pad
440- T_array ( t, 0 u ) // Body elements
441+ T_array ( t, 1 u ) // Body elements
441442 ) ) ;
442443}
443444
@@ -540,7 +541,14 @@ fn T_tag(type_names tn, uint size) -> TypeRef {
540541 if ( tn. name_has_type ( s) ) {
541542 ret tn. get_type ( s) ;
542543 }
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+
544552 tn. associate ( s, t) ;
545553 ret t;
546554}
@@ -1592,16 +1600,28 @@ fn linearize_ty_params(@block_ctxt cx, ty.t t) ->
15921600}
15931601
15941602fn 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 {
15971605 auto llmyroottydesc = alloca( cx, T_tydesc ( cx. fcx. lcx. ccx. tn) ) ;
15981606
15991607 // By convention, desc 0 is the root descriptor.
16001608 llroottydesc = cx. build. Load ( llroottydesc) ;
16011609 cx. build. Store ( llroottydesc, llmyroottydesc) ;
16021610
16031611 // 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+ }
16051625 cx. build. Store ( llfirstparam,
16061626 cx. build. GEP ( llmyroottydesc, vec( C_int ( 0 ) , C_int ( 0 ) ) ) ) ;
16071627
@@ -1650,18 +1670,26 @@ fn mk_derived_tydesc(@block_ctxt cx, ty.t t, bool escapes) -> result {
16501670 C_int ( ( 1 u + n_params) as int) ,
16511671 vp2i( bcx, tydescs) ) , true) ;
16521672 } 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) ) ;
16551679
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) ;
16611689 }
16621690
16631691 v = trans_stack_local_derived_tydesc ( bcx, sz. val , align. val , root,
1664- llparamtydescs ) ;
1692+ llparamtydescs_opt ) ;
16651693 }
16661694
16671695 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,
42694297 auto body = next_cx. build. GEP ( v, vec( C_int ( 0 ) , C_int ( abi. vec_elt_data) ) ) ;
42704298 auto elt;
42714299 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 ) ) ) ;
42734301 elt = next_cx. build. GEP ( body, vec( C_int ( 0 ) , scaled_ix) ) ;
42744302 } else {
42754303 elt = next_cx. build. GEP ( body, vec( C_int ( 0 ) , ix_val) ) ;
0 commit comments