File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ // check-pass
2+ // known-bug: #49682
3+ // edition:2021
4+
5+ // Should fail. Keeping references to thread local statics can result in a
6+ // use-after-free.
7+
8+ #![ feature( thread_local) ]
9+
10+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
11+ use std:: thread;
12+
13+ #[ allow( dead_code) ]
14+ #[ thread_local]
15+ static FOO : AtomicUsize = AtomicUsize :: new ( 0 ) ;
16+
17+ #[ allow( dead_code) ]
18+ async fn bar ( ) { }
19+
20+ #[ allow( dead_code) ]
21+ async fn foo ( ) {
22+ let r = & FOO ;
23+ bar ( ) . await ;
24+ r. load ( Ordering :: SeqCst ) ;
25+ }
26+
27+ fn main ( ) {
28+ // &FOO = 0x7fd1e9cbf6d0
29+ _ = thread:: spawn ( || {
30+ let g = foo ( ) ;
31+ println ! ( "&FOO = {:p}" , & FOO ) ;
32+ g
33+ } )
34+ . join ( )
35+ . unwrap ( ) ;
36+
37+ // &FOO = 0x7fd1e9cc0f50
38+ println ! ( "&FOO = {:p}" , & FOO ) ;
39+
40+ // &FOO = 0x7fd1e9cbf6d0
41+ thread:: spawn ( move || {
42+ println ! ( "&FOO = {:p}" , & FOO ) ;
43+ } )
44+ . join ( )
45+ . unwrap ( ) ;
46+ }
You can’t perform that action at this time.
0 commit comments