Skip to content

Commit 15c7965

Browse files
committed
test handling of stack overflow in TLS destructor
1 parent f5f93d0 commit 15c7965

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/ui/abi/stack-probes.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ fn main() {
2727
if args.len() > 0 {
2828
match &args[0][..] {
2929
"main-recurse" => overflow_recurse(),
30+
"main-tls-recurse" => tls_recurse(),
3031
"child-recurse" => thread::spawn(overflow_recurse).join().unwrap(),
32+
"child-tls-recurse" => thread::spawn(tls_recurse).join().unwrap(),
3133
"child-frame" => overflow_frame(),
3234
_ => panic!(),
3335
}
@@ -42,8 +44,10 @@ fn main() {
4244
// details
4345
if cfg!(not(target_os = "linux")) {
4446
assert_overflow(Command::new(&me).arg("main-recurse"));
47+
assert_overflow(Command::new(&me).arg("main-tls-recurse"));
4548
}
4649
assert_overflow(Command::new(&me).arg("child-recurse"));
50+
assert_overflow(Command::new(&me).arg("child-tls-recurse"));
4751
assert_overflow(Command::new(&me).arg("child-frame"));
4852
}
4953

@@ -56,6 +60,20 @@ fn recurse(array: &MaybeUninit<[u64; 1024]>) {
5660
recurse(&local);
5761
}
5862

63+
fn tls_recurse() {
64+
struct RecursiveDrop;
65+
66+
impl Drop for RecursiveDrop {
67+
fn drop(&mut self) {
68+
overflow_recurse();
69+
}
70+
}
71+
72+
thread_local!(static LOCAL: RecursiveDrop = const { RecursiveDrop });
73+
74+
LOCAL.with(|_| {});
75+
}
76+
5977
#[inline(never)]
6078
fn overflow_recurse() {
6179
recurse(&MaybeUninit::uninit());

0 commit comments

Comments
 (0)