File tree 2 files changed +94
-0
lines changed
src/test/ui/panic-runtime
2 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ // build-pass
2
+ // compile-flags: -C panic=unwind -C target-feature=+crt-static
3
+ // only-msvc
4
+ // Test that `no_std` with `panic=unwind` under MSVC toolchain
5
+ // doesn't cause error when linking to libcmt.
6
+
7
+ #![ no_std]
8
+ #![ no_main]
9
+ #![ feature( alloc_error_handler) ]
10
+ #![ feature( panic_unwind) ]
11
+
12
+ use core:: alloc:: { GlobalAlloc , Layout } ;
13
+
14
+ struct DummyAllocator ;
15
+
16
+ unsafe impl GlobalAlloc for DummyAllocator {
17
+ unsafe fn alloc ( & self , _layout : Layout ) -> * mut u8 {
18
+ core:: ptr:: null_mut ( )
19
+ }
20
+
21
+ unsafe fn dealloc ( & self , _ptr : * mut u8 , _layout : Layout ) { }
22
+ }
23
+
24
+ #[ global_allocator]
25
+ static ALLOC : DummyAllocator = DummyAllocator ;
26
+
27
+ #[ alloc_error_handler]
28
+ fn rust_oom ( _layout : Layout ) -> ! {
29
+ panic ! ( )
30
+ }
31
+
32
+ extern crate panic_unwind;
33
+
34
+ use core:: panic:: PanicInfo ;
35
+
36
+ #[ panic_handler]
37
+ fn handle_panic ( _: & PanicInfo ) -> ! {
38
+ loop { }
39
+ }
40
+
41
+ #[ link( name = "libcmt" ) ]
42
+ extern "C" { }
43
+
44
+ #[ no_mangle]
45
+ pub extern "C" fn main ( ) -> i32 {
46
+ panic ! ( ) ;
47
+ }
Original file line number Diff line number Diff line change
1
+ // build-pass
2
+ // compile-flags: -C panic=unwind
3
+ // only-msvc
4
+ // Test that `no_std` with `panic=unwind` under MSVC toolchain
5
+ // doesn't cause error when linking to msvcrt.
6
+
7
+ #![ no_std]
8
+ #![ no_main]
9
+ #![ feature( alloc_error_handler) ]
10
+ #![ feature( panic_unwind) ]
11
+
12
+ use core:: alloc:: { GlobalAlloc , Layout } ;
13
+
14
+ struct DummyAllocator ;
15
+
16
+ unsafe impl GlobalAlloc for DummyAllocator {
17
+ unsafe fn alloc ( & self , _layout : Layout ) -> * mut u8 {
18
+ core:: ptr:: null_mut ( )
19
+ }
20
+
21
+ unsafe fn dealloc ( & self , _ptr : * mut u8 , _layout : Layout ) { }
22
+ }
23
+
24
+ #[ global_allocator]
25
+ static ALLOC : DummyAllocator = DummyAllocator ;
26
+
27
+ #[ alloc_error_handler]
28
+ fn rust_oom ( _layout : Layout ) -> ! {
29
+ panic ! ( )
30
+ }
31
+
32
+ extern crate panic_unwind;
33
+
34
+ use core:: panic:: PanicInfo ;
35
+
36
+ #[ panic_handler]
37
+ fn handle_panic ( _: & PanicInfo ) -> ! {
38
+ loop { }
39
+ }
40
+
41
+ #[ link( name = "msvcrt" ) ]
42
+ extern "C" { }
43
+
44
+ #[ no_mangle]
45
+ pub extern "C" fn main ( ) -> i32 {
46
+ panic ! ( ) ;
47
+ }
You can’t perform that action at this time.
0 commit comments