Skip to content

Commit 092e7a7

Browse files
committed
Fix segfault related to __builtin_unreachable with inline asm
1 parent 9b2d8e5 commit 092e7a7

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/asm.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
575575
}
576576
if dest.is_none() && options.contains(InlineAsmOptions::NORETURN) {
577577
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
578-
let builtin_unreachable: RValue<'gcc> =
579-
unsafe { std::mem::transmute(builtin_unreachable) };
580-
self.call(self.type_void(), None, None, builtin_unreachable, &[], None, None);
578+
let _ = self.context.new_call(None, builtin_unreachable, &[]);
581579
}
582580

583581
// Write results to outputs.

tests/run/unreachable-function.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Compiler:
2+
//
3+
// Run-time:
4+
// status: 0
5+
6+
use std::arch::asm;
7+
8+
fn exit_syscall(status: i32) -> ! {
9+
unsafe {
10+
asm!(
11+
"syscall",
12+
in("rax") 60, // assuming x86_64 Linux
13+
in("rdi") status,
14+
options(noreturn)
15+
);
16+
}
17+
}
18+
19+
fn main() {
20+
// Used to crash with rustc_codegen_gcc.
21+
exit_syscall(0);
22+
std::process::exit(1);
23+
}

0 commit comments

Comments
 (0)