-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Beta segfault regression #37222
Comments
This looks very similar to #36401. |
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 8 The 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 |
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:
|
Waiting on backport. |
trans: pad const structs to aligned size Fixes #37222. I'm not sure if that is the *correct* way to fix this, but it *does* work.
trans: pad const structs to aligned size Fixes #37222. I'm not sure if that is the *correct* way to fix this, but it *does* work.
Reopened because this still affects beta. |
Backported in #37344, so closing. |
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
The text was updated successfully, but these errors were encountered: