1
Fork 0

rustc: Stop emitting zero-length arrays

This commit is contained in:
Patrick Walton 2011-05-08 16:24:24 -07:00
parent db3b9a4992
commit 106216d673

View file

@ -429,6 +429,7 @@ fn T_tydesc(type_names tn) -> TypeRef {
} }
fn T_array(TypeRef t, uint n) -> TypeRef { fn T_array(TypeRef t, uint n) -> TypeRef {
assert (n != 0u);
ret llvm.LLVMArrayType(t, n); ret llvm.LLVMArrayType(t, n);
} }
@ -437,7 +438,7 @@ fn T_vec(TypeRef t) -> TypeRef {
T_int(), // Alloc T_int(), // Alloc
T_int(), // Fill T_int(), // Fill
T_int(), // Pad T_int(), // Pad
T_array(t, 0u) // Body elements T_array(t, 1u) // Body elements
)); ));
} }
@ -540,7 +541,14 @@ fn T_tag(type_names tn, uint size) -> TypeRef {
if (tn.name_has_type(s)) { if (tn.name_has_type(s)) {
ret tn.get_type(s); ret tn.get_type(s);
} }
auto t = T_struct(vec(T_int(), T_array(T_i8(), size)));
auto t;
if (size == 0u) {
t = T_struct(vec(T_int()));
} else {
t = T_struct(vec(T_int(), T_array(T_i8(), size)));
}
tn.associate(s, t); tn.associate(s, t);
ret t; ret t;
} }
@ -1592,8 +1600,8 @@ fn linearize_ty_params(@block_ctxt cx, ty.t t) ->
} }
fn trans_stack_local_derived_tydesc(@block_ctxt cx, ValueRef llsz, fn trans_stack_local_derived_tydesc(@block_ctxt cx, ValueRef llsz,
ValueRef llalign, ValueRef llroottydesc, ValueRef llparamtydescs) ValueRef llalign, ValueRef llroottydesc,
-> result { Option.t[ValueRef] llparamtydescs) -> result {
auto llmyroottydesc = alloca(cx, T_tydesc(cx.fcx.lcx.ccx.tn)); auto llmyroottydesc = alloca(cx, T_tydesc(cx.fcx.lcx.ccx.tn));
// By convention, desc 0 is the root descriptor. // By convention, desc 0 is the root descriptor.
@ -1601,7 +1609,19 @@ fn trans_stack_local_derived_tydesc(@block_ctxt cx, ValueRef llsz,
cx.build.Store(llroottydesc, llmyroottydesc); cx.build.Store(llroottydesc, llmyroottydesc);
// Store a pointer to the rest of the descriptors. // Store a pointer to the rest of the descriptors.
auto llfirstparam = cx.build.GEP(llparamtydescs, vec(C_int(0), C_int(0))); auto llrootfirstparam = cx.build.GEP(llmyroottydesc,
vec(C_int(0), C_int(0)));
auto llfirstparam;
alt (llparamtydescs) {
case (none[ValueRef]) {
llfirstparam = C_null(val_ty(llrootfirstparam));
}
case (some[ValueRef](?llparamtydescs)) {
llfirstparam = cx.build.GEP(llparamtydescs,
vec(C_int(0), C_int(0)));
}
}
cx.build.Store(llfirstparam, cx.build.Store(llfirstparam,
cx.build.GEP(llmyroottydesc, vec(C_int(0), C_int(0)))); cx.build.GEP(llmyroottydesc, vec(C_int(0), C_int(0))));
@ -1650,18 +1670,26 @@ fn mk_derived_tydesc(@block_ctxt cx, ty.t t, bool escapes) -> result {
C_int((1u + n_params) as int), C_int((1u + n_params) as int),
vp2i(bcx, tydescs)), true); vp2i(bcx, tydescs)), true);
} else { } else {
auto llparamtydescs = alloca(cx, auto llparamtydescs_opt;
T_array(T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn)), n_params)); if (n_params == 0u) {
llparamtydescs_opt = none[ValueRef];
} else {
auto llparamtydescs = alloca(cx,
T_array(T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn)), n_params));
auto i = 0; auto i = 0;
for (ValueRef td in tys._1) { for (ValueRef td in tys._1) {
auto tdp = cx.build.GEP(llparamtydescs, vec(C_int(0), C_int(i))); auto tdp = cx.build.GEP(llparamtydescs,
cx.build.Store(td, tdp); vec(C_int(0), C_int(i)));
i += 1; cx.build.Store(td, tdp);
i += 1;
}
llparamtydescs_opt = some[ValueRef](llparamtydescs);
} }
v = trans_stack_local_derived_tydesc(bcx, sz.val, align.val, root, v = trans_stack_local_derived_tydesc(bcx, sz.val, align.val, root,
llparamtydescs); llparamtydescs_opt);
} }
ret res(v.bcx, vi2p(v.bcx, v.val, T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn)))); 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,
auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data))); auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data)));
auto elt; auto elt;
if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, unit_ty)) { if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, unit_ty)) {
body = next_cx.build.PointerCast(body, T_ptr(T_array(T_i8(), 0u))); body = next_cx.build.PointerCast(body, T_ptr(T_array(T_i8(), 1u)));
elt = next_cx.build.GEP(body, vec(C_int(0), scaled_ix)); elt = next_cx.build.GEP(body, vec(C_int(0), scaled_ix));
} else { } else {
elt = next_cx.build.GEP(body, vec(C_int(0), ix_val)); elt = next_cx.build.GEP(body, vec(C_int(0), ix_val));