Skip to content

Commit 8e9ccdf

Browse files
committed
add tests for asm's options(may_unwind)
1 parent 686ace3 commit 8e9ccdf

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

src/test/codegen/asm-may_unwind.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// min-llvm-version: 13.0.0
2+
// compile-flags: -O
3+
4+
#![crate_type = "rlib"]
5+
#![feature(asm, asm_unwind)]
6+
7+
#[no_mangle]
8+
pub extern "C" fn panicky() {}
9+
10+
struct Foo;
11+
12+
impl Drop for Foo {
13+
fn drop(&mut self) {
14+
println!();
15+
}
16+
}
17+
18+
// CHECK-LABEL: @may_unwind
19+
// CHECK: invoke void asm sideeffect alignstack unwind
20+
#[no_mangle]
21+
pub unsafe fn may_unwind() {
22+
let _m = Foo;
23+
asm!("", options(may_unwind));
24+
}

src/test/ui/asm/aarch64/may_unwind.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// min-llvm-version: 13.0.0
2+
// only-aarch64
3+
// run-pass
4+
// needs-asm-support
5+
6+
#![feature(asm, asm_unwind)]
7+
8+
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
9+
10+
struct Foo<'a>(&'a mut bool);
11+
12+
impl Drop for Foo<'_> {
13+
fn drop(&mut self) {
14+
*self.0 = false;
15+
}
16+
}
17+
18+
#[no_mangle]
19+
extern "C" fn panicky() {
20+
resume_unwind(Box::new(()));
21+
}
22+
23+
fn main() {
24+
let flag = &mut true;
25+
catch_unwind(AssertUnwindSafe(|| {
26+
let _foo = Foo(flag);
27+
unsafe { asm!("bl _panicky", options(may_unwind)) };
28+
}))
29+
.expect_err("expected a panic");
30+
assert_eq!(*flag, false);
31+
}

src/test/ui/asm/may_unwind.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// min-llvm-version: 13.0.0
2+
// run-pass
3+
// needs-asm-support
4+
5+
#![feature(asm, asm_unwind)]
6+
7+
fn main() {
8+
unsafe { asm!("", options(may_unwind)) };
9+
}

src/test/ui/asm/x86_64/may_unwind.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// min-llvm-version: 13.0.0
2+
// only-x86_64
3+
// run-pass
4+
// needs-asm-support
5+
6+
#![feature(asm, asm_unwind)]
7+
8+
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
9+
10+
struct Foo<'a>(&'a mut bool);
11+
12+
impl Drop for Foo<'_> {
13+
fn drop(&mut self) {
14+
*self.0 = false;
15+
}
16+
}
17+
18+
#[no_mangle]
19+
extern "C" fn panicky() {
20+
resume_unwind(Box::new(()));
21+
}
22+
23+
fn main() {
24+
let flag = &mut true;
25+
catch_unwind(AssertUnwindSafe(|| {
26+
let _foo = Foo(flag);
27+
unsafe { asm!("call panicky", options(may_unwind)) };
28+
}))
29+
.expect_err("expected a panic");
30+
assert_eq!(*flag, false);
31+
}

0 commit comments

Comments
 (0)