Skip to content

Commit cb1f957

Browse files
committed
rustc: fix const enums to be packed, r=burningtree.
1 parent 4f88ed3 commit cb1f957

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/librustc/middle/trans/common.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,14 @@ fn C_struct(elts: &[ValueRef]) -> ValueRef {
12091209
}
12101210
}
12111211
1212+
fn C_packed_struct(elts: &[ValueRef]) -> ValueRef {
1213+
unsafe {
1214+
do vec::as_imm_buf(elts) |ptr, len| {
1215+
llvm::LLVMConstStruct(ptr, len as c_uint, True)
1216+
}
1217+
}
1218+
}
1219+
12121220
fn C_named_struct(T: TypeRef, elts: &[ValueRef]) -> ValueRef {
12131221
unsafe {
12141222
do vec::as_imm_buf(elts) |ptr, len| {

src/librustc/middle/trans/consts.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,14 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
455455
let discrim = base::get_discrim_val(cx, e.span, tid, vid);
456456
let c_args = C_struct(args.map(|a| const_expr(cx, *a)));
457457

458-
let fields = if !degen {
459-
~[discrim, c_args]
458+
// FIXME (#1645): enum body alignment is generaly wrong.
459+
if !degen {
460+
C_packed_struct(~[discrim, c_args])
460461
} else if size == 0 {
461-
~[discrim]
462+
C_struct(~[discrim])
462463
} else {
463-
~[c_args]
464-
};
465-
466-
C_struct(fields)
464+
C_struct(~[c_args])
465+
}
467466
}
468467
_ => cx.sess.span_bug(e.span, ~"expected a struct def")
469468
}

0 commit comments

Comments
 (0)