Skip to content

Commit a5030e7

Browse files
committed
Wrap const structs in as many LLVM structs as the non-const case.
This, like the previous change for unit-like enums, is only necessary until everything is fully converted to use trans::adt.
1 parent e09a843 commit a5030e7

File tree

1 file changed

+11
-4
lines changed
  • src/librustc/middle/trans

1 file changed

+11
-4
lines changed

src/librustc/middle/trans/adt.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,15 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
269269
assert min <= discr && discr <= max;
270270
C_int(ccx, discr)
271271
}
272-
Univariant(ref st, _dt) => {
272+
Univariant(ref st, dt) => {
273273
assert discr == 0;
274-
// consts are never destroyed, so the dtor flag is not needed
275-
C_struct(build_const_struct(ccx, st, vals))
274+
let s = C_struct(build_const_struct(ccx, st, vals));
275+
match dt {
276+
NoDtor => s,
277+
// The actual destructor flag doesn't need to be present.
278+
// But add an extra struct layer for compatibility.
279+
DtorPresent | DtorAbsent => C_struct(~[s])
280+
}
276281
}
277282
General(ref cases) => {
278283
let case = &cases[discr as uint];
@@ -336,7 +341,9 @@ pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
336341
match *r {
337342
Unit(*) | CEnum(*) => ccx.sess.bug(~"element access in C-like enum \
338343
const"),
339-
Univariant(*) => const_struct_field(ccx, val, ix),
344+
Univariant(_, NoDtor) => const_struct_field(ccx, val, ix),
345+
Univariant(*) => const_struct_field(ccx, const_get_elt(ccx, val,
346+
[0]), ix),
340347
General(*) => const_struct_field(ccx, const_get_elt(ccx, val,
341348
[1, 0]), ix)
342349
}

0 commit comments

Comments
 (0)