Skip to content

Commit 3bf5eb2

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

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
220220
let bool_type = context.new_type::<bool>();
221221

222222
let mut functions = FxHashMap::default();
223-
let builtins = ["abort"];
223+
let builtins = ["abort", "__builtin_unreachable"];
224224

225225
for builtin in builtins.iter() {
226226
functions.insert(builtin.to_string(), context.get_builtin_function(builtin));

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)