diff options
| author | Jed Davis <jld@panix.com> | 2013-03-06 20:17:22 -0800 |
|---|---|---|
| committer | Jed Davis <jld@panix.com> | 2013-03-06 20:40:42 -0800 |
| commit | a5030e7615f7d37acaee69b13f97b9ffa23159a5 (patch) | |
| tree | 53b28577e0c88e4fc707326e3a8ca69305395007 | |
| parent | e09a843973f8dfc5766c0d36bb68ee1136cbf54c (diff) | |
| download | rust-a5030e7615f7d37acaee69b13f97b9ffa23159a5.tar.gz rust-a5030e7615f7d37acaee69b13f97b9ffa23159a5.zip | |
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.
| -rw-r--r-- | src/librustc/middle/trans/adt.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index b32111f6bf4..c6ba0a7d81f 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -269,10 +269,15 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int, assert min <= discr && discr <= max; C_int(ccx, discr) } - Univariant(ref st, _dt) => { + Univariant(ref st, dt) => { assert discr == 0; - // consts are never destroyed, so the dtor flag is not needed - C_struct(build_const_struct(ccx, st, vals)) + let s = C_struct(build_const_struct(ccx, st, vals)); + match dt { + NoDtor => s, + // The actual destructor flag doesn't need to be present. + // But add an extra struct layer for compatibility. + DtorPresent | DtorAbsent => C_struct(~[s]) + } } General(ref cases) => { let case = &cases[discr as uint]; @@ -336,7 +341,9 @@ pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef, match *r { Unit(*) | CEnum(*) => ccx.sess.bug(~"element access in C-like enum \ const"), - Univariant(*) => const_struct_field(ccx, val, ix), + Univariant(_, NoDtor) => const_struct_field(ccx, val, ix), + Univariant(*) => const_struct_field(ccx, const_get_elt(ccx, val, + [0]), ix), General(*) => const_struct_field(ccx, const_get_elt(ccx, val, [1, 0]), ix) } |
