Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upBeta segfault regression #37222
Comments
This comment has been minimized.
This comment has been minimized.
|
This looks very similar to #36401. |
This comment has been minimized.
This comment has been minimized.
|
This was introduced between I'm no llvm ir expert, however I believe the following excerpts show the problem: ; GOOD
%Binding = type { %Action, i8 }
%Action = type { i8, [7 x i8], [2 x i64] }
@_ZN5newsf10V_BINDINGS17h3669347bdb3d8fc8E = internal constant { %Binding*, i64 } { %Binding* bitcast ({
{ { i8, [23 x i8] }, i8, [7 x i8] },
{ { i8, [23 x i8] }, i8, [7 x i8] }
}* @ref8290 to %Binding*), i64 2 }, align 8
; BAD
%Binding = type { %Action, i8 }
%Action = type { i32, [1 x i32], [2 x i64] }
@_ZN5newsf10V_BINDINGS17h490c5b52b95657e8E = internal constant { %Binding*, i64 } { %Binding* bitcast ({
{ { i32, [20 x i8] }, i8 },
{ { i32, [20 x i8] }, i8 }
}* @ref8293 to %Binding*), i64 2 }, align 8The definition in the Edit: Note that this ir was obtained from a slightly modified code, the static V_BINDINGS: &'static [Binding] = &[
Binding { action: Action::Paste, mode: 0 },
Binding { action: Action::Paste, mode: 1 },
];And the struct changed to pub struct Binding {
action: Action,
mode: u8, // <-- Change is here
}Also, some manually edited |
This comment has been minimized.
This comment has been minimized.
|
The following code reproduces the problem without the segfault: #![feature(core_intrinsics)]
use std::{mem, intrinsics};
pub struct Binding {
action: Action,
mode: u8,
}
pub enum Action {
Esc(i64),
Char(u32),
Paste,
}
static V_BINDINGS: &'static [Binding] = &[
Binding { action: Action::Paste, mode: 0xff },
Binding { action: Action::Paste, mode: 0xff },
];
fn main() {
let first = unsafe { intrinsics::discriminant_value(&V_BINDINGS[0].action) };
let second = unsafe { intrinsics::discriminant_value(&V_BINDINGS[1].action) };
// Edit: added the next three asserts.
assert_eq!(mem::size_of::<Action>(), 16);
assert_eq!(mem::size_of::<Binding>(), 24);
assert_eq!(&V_BINDINGS[1] as *const _ as usize - &V_BINDINGS[0] as *const _ as usize, 24);
// Edit: added hexdump
let start = &V_BINDINGS[0] as *const _ as *const u8;
for i in 0 .. 48 {
print!("{:02X} ", unsafe { *start.offset(i) });
if i % 24 == 23 { println!(""); }
}
assert_eq!(first, 2);
assert_eq!(second, 2); // <-- This fails
}The expected hexdump would be (from the working nightly):
The actual hexdump is:
|
brson
added
I-crash
P-high
labels
Oct 20, 2016
This comment has been minimized.
This comment has been minimized.
|
Waiting on backport. |
nikomatsakis
removed
the
I-nominated
label
Oct 20, 2016
bors
added a commit
that referenced
this issue
Oct 21, 2016
bors
added a commit
that referenced
this issue
Oct 21, 2016
bors
added a commit
that referenced
this issue
Oct 22, 2016
bors
closed this
in
#37281
Oct 22, 2016
This comment has been minimized.
This comment has been minimized.
|
Reopened because this still affects beta. |
TimNN
reopened this
Oct 22, 2016
TimNN
referenced this issue
Oct 22, 2016
Merged
[beta] trans: pad const structs to aligned size #37344
This comment has been minimized.
This comment has been minimized.
|
Backported in #37344, so closing. |
alexcrichton commentedOct 16, 2016
Running this code in either release or debug mode will yield a segfault:
It looks like this also runs successfully on stable, just failing on beta/nightly
cc @jwilm