]> git.lizzy.rs Git - rust.git/blob - tests/debuginfo/function-names.rs
Merge commit '7d53619064ab7045c383644cb445052d2a3d46db' into sync_cg_clif-2023-02-09
[rust.git] / tests / debuginfo / function-names.rs
1 // Function names are formatted differently in old versions of GDB
2 // min-gdb-version: 10.1
3
4 // compile-flags:-g
5
6 // === GDB TESTS ===================================================================================
7
8 // Top-level function
9 // gdb-command:info functions -q function_names::main
10 // gdb-check:[...]static fn function_names::main();
11 // gdb-command:info functions -q function_names::generic_func<*
12 // gdb-check:[...]static fn function_names::generic_func<i32>(i32) -> i32;
13
14 // Implementations
15 // gdb-command:info functions -q function_names::.*::impl_function.*
16 // gdb-check:[...]static fn function_names::GenericStruct<i32, i32>::impl_function<i32, i32>();
17 // gdb-check:[...]static fn function_names::Mod1::TestStruct2::impl_function();
18 // gdb-check:[...]static fn function_names::TestStruct1::impl_function();
19
20 // Trait implementations
21 // gdb-command:info functions -q function_names::.*::trait_function.*
22 // gdb-check:[...]static fn function_names::Mod1::{impl#1}::trait_function();
23 // gdb-check:[...]static fn function_names::{impl#1}::trait_function();
24 // gdb-check:[...]static fn function_names::{impl#3}::trait_function<i32>();
25 // gdb-check:[...]static fn function_names::{impl#5}::trait_function3<function_names::TestStruct1>();
26 // gdb-check:[...]static fn function_names::{impl#6}::trait_function<i32, 1>();
27
28 // Closure
29 // gdb-command:info functions -q function_names::.*::{closure.*
30 // gdb-check:[...]static fn function_names::generic_func::{closure#0}<i32>(*mut function_names::generic_func::{closure_env#0}<i32>);
31 // gdb-check:[...]static fn function_names::main::{closure#0}(*mut function_names::main::{closure_env#0});
32 // gdb-check:[...]static fn function_names::{impl#2}::impl_function::{closure#0}<i32, i32>(*mut function_names::{impl#2}::impl_function::{closure_env#0}<i32, i32>);
33
34 // Generator
35 // Generators don't seem to appear in GDB's symbol table.
36
37 // Const generic parameter
38 // gdb-command:info functions -q function_names::const_generic_fn.*
39 // gdb-check:[...]static fn function_names::const_generic_fn_bool<false>();
40 // gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#6348c650c7b26618}>();
41 // gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>();
42 // gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>();
43
44 // === CDB TESTS ===================================================================================
45
46 // Top-level function
47 // cdb-command:x a!function_names::main
48 // cdb-check:[...] a!function_names::main (void)
49 // cdb-command:x a!function_names::generic_func<*
50 // cdb-check:[...] a!function_names::generic_func<i32> (int)
51
52 // Implementations
53 // cdb-command:x a!function_names::*::impl_function*
54 // cdb-check:[...] a!function_names::Mod1::TestStruct2::impl_function (void)
55 // cdb-check:[...] a!function_names::TestStruct1::impl_function (void)
56 // cdb-check:[...] a!function_names::GenericStruct<i32,i32>::impl_function<i32,i32> (void)
57
58 // Trait implementations
59 // cdb-command:x a!function_names::*::trait_function*
60 // cdb-check:[...] a!function_names::impl$3::trait_function<i32> (void)
61 // cdb-check:[...] a!function_names::impl$6::trait_function<i32,1> (void)
62 // cdb-check:[...] a!function_names::impl$1::trait_function (void)
63 // cdb-check:[...] a!function_names::impl$5::trait_function3<function_names::TestStruct1> (void)
64 // cdb-check:[...] a!function_names::Mod1::impl$1::trait_function (void)
65
66 // Closure
67 // cdb-command:x a!function_names::*::closure*
68 // cdb-check:[...] a!function_names::impl$2::impl_function::closure$0<i32,i32> (void)
69 // cdb-check:[...] a!function_names::main::closure$0 (void)
70 // cdb-check:[...] a!function_names::generic_func::closure$0<i32> (void)
71
72 // Generator
73 // cdb-command:x a!function_names::*::generator*
74 // cdb-check:[...] a!function_names::main::generator$1 (void)
75
76 // Const generic parameter
77 // cdb-command:x a!function_names::const_generic_fn*
78 // cdb-check:[...] a!function_names::const_generic_fn_bool<false> (void)
79 // cdb-check:[...] a!function_names::const_generic_fn_unsigned_int<14> (void)
80 // cdb-check:[...] a!function_names::const_generic_fn_signed_int<-7> (void)
81 // cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$6348c650c7b26618> (void)
82
83 #![allow(unused_variables)]
84 #![feature(omit_gdb_pretty_printer_section)]
85 #![omit_gdb_pretty_printer_section]
86 #![feature(adt_const_params, generators, generator_trait)]
87 #![allow(incomplete_features)]
88
89 use std::ops::Generator;
90 use std::pin::Pin;
91 use Mod1::TestTrait2;
92
93 fn main() {
94     // Implementations
95     TestStruct1::impl_function();
96     Mod1::TestStruct2::impl_function();
97     GenericStruct::<i32, i32>::impl_function();
98
99     // Trait implementations
100     TestStruct1::trait_function();
101     Mod1::TestStruct2::trait_function();
102     GenericStruct::<i32, i32>::trait_function();
103     GenericStruct::<[i32; 1], f32>::trait_function();
104     GenericStruct::<TestStruct1, usize>::trait_function3();
105
106     // Generic function
107     let _ = generic_func(42i32);
108
109     // Closure
110     let closure = || TestStruct1;
111     closure();
112
113     // Generator
114     let mut generator = || {
115         yield;
116         return;
117     };
118     Pin::new(&mut generator).resume(());
119
120     // Const generic functions
121     const_generic_fn_bool::<false>();
122     const_generic_fn_non_int::<{ () }>();
123     const_generic_fn_signed_int::<-7>();
124     const_generic_fn_unsigned_int::<14>();
125 }
126
127 struct TestStruct1;
128 trait TestTrait1 {
129     fn trait_function();
130 }
131
132 // Implementation
133 impl TestStruct1 {
134     pub fn impl_function() {}
135 }
136
137 // Implementation for a trait
138 impl TestTrait1 for TestStruct1 {
139     fn trait_function() {}
140 }
141
142 // Implementation and implementation within a mod
143 mod Mod1 {
144     pub struct TestStruct2;
145     pub trait TestTrait2 {
146         fn trait_function();
147     }
148
149     impl TestStruct2 {
150         pub fn impl_function() {}
151     }
152
153     impl TestTrait2 for TestStruct2 {
154         fn trait_function() {}
155     }
156 }
157
158 struct GenericStruct<T1, T2>(std::marker::PhantomData<(T1, T2)>);
159
160 // Generic implementation
161 impl<T1, T2> GenericStruct<T1, T2> {
162     pub fn impl_function() {
163         // Closure in a generic implementation
164         let closure = || TestStruct1;
165         closure();
166     }
167 }
168
169 // Generic trait implementation
170 impl<T> TestTrait1 for GenericStruct<T, i32> {
171     fn trait_function() {}
172 }
173
174 // Implementation based on associated type
175 trait TestTrait3 {
176     type AssocType;
177     fn trait_function3();
178 }
179 impl TestTrait3 for TestStruct1 {
180     type AssocType = usize;
181     fn trait_function3() {}
182 }
183 impl<T: TestTrait3> TestTrait3 for GenericStruct<T, T::AssocType> {
184     type AssocType = T::AssocType;
185     fn trait_function3() {}
186 }
187
188 // Generic trait implementation with const generics
189 impl<T, const N: usize> TestTrait1 for GenericStruct<[T; N], f32> {
190     fn trait_function() {}
191 }
192
193 // Generic function
194 fn generic_func<T>(value: T) -> T {
195     // Closure in a generic function
196     let closure = || TestStruct1;
197     closure();
198
199     value
200 }
201
202 fn const_generic_fn_bool<const C: bool>() {}
203 fn const_generic_fn_non_int<const C: ()>() {}
204 fn const_generic_fn_signed_int<const C: i64>() {}
205 fn const_generic_fn_unsigned_int<const C: u32>() {}