Merge pull request #834 from rust-lang/fix/unreachable-segfault
Fix segfault related to __builtin_unreachable with inline asm
This commit is contained in:
commit
bcb24ceaba
2 changed files with 28 additions and 3 deletions
|
|
@ -575,9 +575,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
}
|
||||
if dest.is_none() && options.contains(InlineAsmOptions::NORETURN) {
|
||||
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
|
||||
let builtin_unreachable: RValue<'gcc> =
|
||||
unsafe { std::mem::transmute(builtin_unreachable) };
|
||||
self.call(self.type_void(), None, None, builtin_unreachable, &[], None, None);
|
||||
self.llbb().add_eval(None, self.context.new_call(None, builtin_unreachable, &[]));
|
||||
}
|
||||
|
||||
// Write results to outputs.
|
||||
|
|
|
|||
27
tests/run/unreachable-function.rs
Normal file
27
tests/run/unreachable-function.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Compiler:
|
||||
//
|
||||
// Run-time:
|
||||
// status: 0
|
||||
|
||||
use std::arch::asm;
|
||||
|
||||
fn exit_syscall(status: i32) -> ! {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
unsafe {
|
||||
asm!(
|
||||
"syscall",
|
||||
in("rax") 60,
|
||||
in("rdi") status,
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "x86_64"))]
|
||||
std::process::exit(status);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Used to crash with rustc_codegen_gcc.
|
||||
exit_syscall(0);
|
||||
std::process::exit(1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue