Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE on statics with fancy nullable enums. #12703

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/librustc/middle/trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,14 +749,15 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
let contents = build_const_struct(ccx, st, vals);
C_struct(contents, st.packed)
}
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
NullablePointer{ nonnull: ref nonnull, nndiscr, .. } => {
if discr == nndiscr {
C_struct(build_const_struct(ccx, nonnull, vals), false)
} else {
let vals = nonnull.fields.iter().enumerate().map(|(i, &ty)| {
let llty = type_of::sizing_type_of(ccx, ty);
if i == ptrfield { C_null(llty) } else { C_undef(llty) }
}).collect::<~[ValueRef]>();
let vals = nonnull.fields.map(|&ty| {
// Always use null even if it's not the `ptrfield`th
// field; see #8506.
C_null(type_of::sizing_type_of(ccx, ty))
});
C_struct(build_const_struct(ccx, nonnull, vals), false)
}
}
Expand Down Expand Up @@ -791,14 +792,8 @@ fn build_const_struct(ccx: &CrateContext, st: &Struct, vals: &[ValueRef])
cfields.push(padding(target_offset - offset));
offset = target_offset;
}
let val = if is_undef(vals[i]) {
let wrapped = C_struct([vals[i]], false);
assert!(!is_undef(wrapped));
wrapped
} else {
vals[i]
};
cfields.push(val);
assert!(!is_undef(vals[i]));
cfields.push(vals[i]);
offset += machine::llsize_of_alloc(ccx, llty) as u64
}

Expand Down
20 changes: 20 additions & 0 deletions src/test/run-pass/issue-8506.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[allow(dead_code)];

enum Either {
One,
Other(~str,~str)
}

static one : Either = One;

pub fn main () { }