From 40b455792d441ef431dfb4de6bdfe082d104269b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 30 May 2013 17:08:49 -0700 Subject: [PATCH] librustc: Bump the offset when translating const structs. Closes #6352. --- src/librustc/middle/trans/adt.rs | 1 + src/test/run-pass/const-struct-offsets.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/test/run-pass/const-struct-offsets.rs diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 4d1c4851e1f6b..b26f80fc355b1 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -563,6 +563,7 @@ fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef]) vals[i] }; cfields.push(val); + offset += machine::llsize_of_alloc(ccx, llty) as u64 } return cfields; diff --git a/src/test/run-pass/const-struct-offsets.rs b/src/test/run-pass/const-struct-offsets.rs new file mode 100644 index 0000000000000..0966fa055bfdd --- /dev/null +++ b/src/test/run-pass/const-struct-offsets.rs @@ -0,0 +1,14 @@ +enum Foo { + IntVal(i32), + Int64Val(i64) +} + +struct Bar { + i: i32, + v: Foo +} + +static bar: Bar = Bar { i: 0, v: IntVal(0) }; + +fn main() {} +