Skip to content

Commit 21e42ad

Browse files
committed
rustc: For derived tydescs, explicitly store 0 for size and align when the type in question has a dynamic size
1 parent c19e4e1 commit 21e42ad

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,19 @@ fn make_tydesc(@crate_ctxt cx, @ty.t t, vec[ast.def_id] typaram_defs) {
12011201
auto dg = make_drop_glue;
12021202
auto drop_glue = make_generic_glue(cx, t, "drop", dg, typaram_defs);
12031203

1204-
auto llty = type_of(cx, t);
1204+
auto llsize;
1205+
auto llalign;
1206+
if (!ty.type_has_dynamic_size(t)) {
1207+
auto llty = type_of(cx, t);
1208+
llsize = llsize_of(llty);
1209+
llalign = llalign_of(llty);
1210+
} else {
1211+
// These will be overwritten as the derived tydesc is generated, so
1212+
// we create placeholder values.
1213+
llsize = C_int(0);
1214+
llalign = C_int(0);
1215+
}
1216+
12051217
auto glue_fn_ty = T_ptr(T_glue_fn(cx.tn));
12061218

12071219
// FIXME: this adjustment has to do with the ridiculous encoding of
@@ -1218,8 +1230,8 @@ fn make_tydesc(@crate_ctxt cx, @ty.t t, vec[ast.def_id] typaram_defs) {
12181230
auto gvar = llvm.LLVMAddGlobal(cx.llmod, T_tydesc(cx.tn),
12191231
_str.buf(name));
12201232
auto tydesc = C_struct(vec(C_null(T_ptr(T_ptr(T_tydesc(cx.tn)))),
1221-
llsize_of(llty),
1222-
llalign_of(llty),
1233+
llsize,
1234+
llalign,
12231235
off(gvar, take_glue), // take_glue_off
12241236
off(gvar, drop_glue), // drop_glue_off
12251237
C_null(glue_fn_ty), // free_glue_off

0 commit comments

Comments
 (0)