Skip to content

Commit 7bd30f8

Browse files
committed
Put out burning tree (sizeof / alignof bug).
1 parent 490da35 commit 7bd30f8

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/comp/middle/trans.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,21 @@ fn find_scope_cx(@block_ctxt cx) -> @block_ctxt {
549549
}
550550
}
551551

552+
fn size_of(TypeRef t) -> ValueRef {
553+
ret llvm.LLVMConstIntCast(lib.llvm.llvm.LLVMSizeOf(t), T_int(), False);
554+
}
555+
556+
fn align_of(TypeRef t) -> ValueRef {
557+
ret llvm.LLVMConstIntCast(lib.llvm.llvm.LLVMAlignOf(t), T_int(), False);
558+
}
559+
552560
fn trans_malloc(@block_ctxt cx, @typeck.ty t) -> result {
553561
auto scope_cx = find_scope_cx(cx);
554562
auto ptr_ty = type_of(cx.fcx.ccx, t);
555563
auto body_ty = lib.llvm.llvm.LLVMGetElementType(ptr_ty);
556564
// FIXME: need a table to collect tydesc globals.
557565
auto tydesc = C_int(0);
558-
auto sz = cx.build.IntCast(lib.llvm.llvm.LLVMSizeOf(body_ty), T_int());
566+
auto sz = size_of(body_ty);
559567
auto sub = trans_upcall(cx, "upcall_malloc", vec(sz, tydesc));
560568
sub.val = sub.bcx.build.IntToPtr(sub.val, ptr_ty);
561569
scope_cx.cleanups += clean(bind drop_ty(_, sub.val, t));
@@ -590,8 +598,8 @@ fn make_tydesc(@crate_ctxt cx, @typeck.ty ty) {
590598
auto pvoid = T_ptr(T_i8());
591599
auto glue_fn_ty = T_ptr(T_fn(vec(T_taskptr(), pvoid), T_void()));
592600
auto tydesc = C_struct(vec(C_null(pvoid),
593-
llvm.LLVMSizeOf(llty),
594-
llvm.LLVMAlignOf(llty),
601+
size_of(llty),
602+
align_of(llty),
595603
take_glue, // copy_glue_off
596604
drop_glue, // drop_glue_off
597605
C_null(glue_fn_ty), // free_glue_off
@@ -924,8 +932,7 @@ fn iter_sequence(@block_ctxt cx,
924932
C_int(abi.vec_elt_fill)));
925933

926934
auto llunit_ty = type_of(cx.fcx.ccx, elt_ty);
927-
auto unit_sz = llvm.LLVMConstIntCast(llvm.LLVMSizeOf(llunit_ty),
928-
T_int(), False);
935+
auto unit_sz = size_of(llunit_ty);
929936

930937
auto len = cx.build.Load(lenptr);
931938
if (trailing_null) {
@@ -1599,8 +1606,8 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
15991606
fail;
16001607
}
16011608

1602-
fn trans_field(@block_ctxt cx, &ast.span sp, @ast.expr base,
1603-
&ast.ident field, &ast.ann ann) -> tup(result, bool) {
1609+
impure fn trans_field(@block_ctxt cx, &ast.span sp, @ast.expr base,
1610+
&ast.ident field, &ast.ann ann) -> tup(result, bool) {
16041611
auto lv = trans_lval(cx, base);
16051612
auto r = lv._0;
16061613
auto ty = typeck.expr_ty(base);
@@ -1621,16 +1628,15 @@ fn trans_field(@block_ctxt cx, &ast.span sp, @ast.expr base,
16211628
fail;
16221629
}
16231630

1624-
fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
1625-
@ast.expr idx, &ast.ann ann) -> tup(result, bool) {
1631+
impure fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
1632+
@ast.expr idx, &ast.ann ann) -> tup(result, bool) {
16261633

16271634
auto lv = trans_expr(cx, base);
16281635
auto ix = trans_expr(lv.bcx, idx);
16291636
auto v = lv.val;
16301637

16311638
auto llunit_ty = node_type(cx.fcx.ccx, ann);
1632-
auto unit_sz = ix.bcx.build.IntCast(lib.llvm.llvm.LLVMSizeOf(llunit_ty),
1633-
T_int());
1639+
auto unit_sz = size_of(llunit_ty);
16341640
auto scaled_ix = ix.bcx.build.Mul(ix.val, unit_sz);
16351641

16361642
auto lim = ix.bcx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_fill)));
@@ -1660,7 +1666,7 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
16601666
// represented as an alloca or heap, hence needs a 'load' to be used as an
16611667
// immediate).
16621668

1663-
fn trans_lval(@block_ctxt cx, @ast.expr e) -> tup(result, bool) {
1669+
impure fn trans_lval(@block_ctxt cx, @ast.expr e) -> tup(result, bool) {
16641670
alt (e.node) {
16651671
case (ast.expr_name(?n, ?dopt, _)) {
16661672
ret trans_name(cx, n, dopt);
@@ -1828,8 +1834,7 @@ impure fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
18281834
}
18291835

18301836
auto llunit_ty = type_of(cx.fcx.ccx, unit_ty);
1831-
auto unit_sz = llvm.LLVMConstIntCast(llvm.LLVMSizeOf(llunit_ty),
1832-
T_int(), False);
1837+
auto unit_sz = size_of(llunit_ty);
18331838
auto data_sz = llvm.LLVMConstMul(C_int(_vec.len[@ast.expr](args) as int),
18341839
unit_sz);
18351840

0 commit comments

Comments
 (0)