xref: /llvm-project/llvm/test/DebugInfo/COFF/trailing-inlined-function.s (revision f2f36c9b2955d2d742a198416f1178fd80303921)
1# REQUIRES: x86-registered-target
2# RUN: llvm-mc -filetype=obj --triple=x86_64-pc-windows-msvc %s | llvm-readobj - --codeview --codeview-subsection-bytes | FileCheck %s
3
4# Rust source to regenerate:
5# #[no_mangle]
6# extern "C" fn add_numbers(x: &Option<i32>, y: &Option<i32>) -> i32 {
7#     let x1 = x.unwrap();
8#     let y1 = y.unwrap();
9#     x1 + y1
10# }
11# $ rustc trailing-inlined-function.rs --crate-type cdylib --emit=asm -Copt-level=3 -Cpanic=abort -Cdebuginfo=1
12
13# Validate that unwrap() was inlined.
14# CHECK:       InlineSiteSym {
15# CHECK-NEXT:    Kind: S_INLINESITE (0x114D)
16# CHECK-NEXT:    PtrParent: 0x0
17# CHECK-NEXT:    PtrEnd: 0x0
18# CHECK-NEXT:    Inlinee: unwrap
19# CHECK-NEXT:    BinaryAnnotations [
20# CHECK-NEXT:      ChangeCodeOffsetAndLineOffset: {CodeOffset: [[#%#x,Offset1_1:]], LineOffset: 1}
21# CHECK-NEXT:      ChangeCodeLength: [[#%#x,Length1_1:]]
22# CHECK-NEXT:      ChangeLineOffset: 2
23# CHECK-NEXT:      ChangeCodeOffset: [[#%#x,Offset1_2:]]
24# CHECK-NEXT:      ChangeCodeLength: [[#%#x,]]
25# CHECK-NEXT:      (Annotation Padding)
26# CHECK:      InlineSiteSym {
27# CHECK-NEXT:    Kind: S_INLINESITE (0x114D)
28# CHECK-NEXT:    PtrParent: 0x0
29# CHECK-NEXT:    PtrEnd: 0x0
30# CHECK-NEXT:    Inlinee: unwrap
31# CHECK-NEXT:    BinaryAnnotations [
32# CHECK-NEXT:      ChangeCodeOffsetAndLineOffset: {CodeOffset: [[#%#x,Offset2_1:]], LineOffset: 1}
33# CHECK-NEXT:      ChangeCodeLength: [[#%#x,Length2_1:]]
34# CHECK-NEXT:      ChangeLineOffset: 2
35# CHECK-NEXT:      ChangeCodeOffset: [[#%#x,Offset2_2:]]
36# CHECK-NEXT:      ChangeCodeLength: [[#%#x,]]
37# CHECK-NEXT:      (Annotation Padding)
38
39# Validate that basic blocks from an inlined function that are sunk below the rest of the function
40# (namely bb1 and bb4 in this test) get the correct debug info.
41# CHECK:       SubSectionType: Lines (0xF2)
42# CHECK-NEXT:   SubSectionSize: [[#%#x,]]
43# CHECK-NEXT:   SubSectionContents (
44# CHECK-NEXT:     0000: [[#%.8X,]] [[#%.8X,]] [[#%.8X,]] [[#%.8X,]]
45#                       Code starts at line 2
46# CHECK-NEXT:     0010: [[#%.8X,]] [[#%.8X,]] [[#%.8X,]] 02000000
47#                       The success paths for unwrap() (lines 3 & 4) are next.
48# CHECK-NEXT:     0020: [[#%.2X,Offset1_1]]000000 03000000 [[#%.2X,Offset2_1]]000000 04000000
49#                       Then the addition (line 5) and the end of the function (end-brace on line 6).
50# CHECK-NEXT:     0030: [[#%.8X,]] 05000000 [[#%.8X,]] 06000000
51#                       The failure paths for unwrap() (lines 3 & 4) are placed after the `ret` instruction.
52# CHECK-NEXT:     0040: [[#%.2X,Offset1_1 + Length1_1 + Offset1_2]]000000 03000000 [[#%.2X,Offset2_1 + Length2_1 + Offset2_2]]000000 04000000
53# CHECK-NOT:    SubSectionType: Lines (0xF2)
54
55	.text
56	.def	@feat.00;
57	.scl	3;
58	.type	0;
59	.endef
60	.globl	@feat.00
61.set @feat.00, 0
62	.file	"trailing_inlined_function.3a6e73a087a7434a-cgu.0"
63	.def	add_numbers;
64	.scl	2;
65	.type	32;
66	.endef
67	.section	.text,"xr",one_only,add_numbers
68	.globl	add_numbers
69	.p2align	4, 0x90
70add_numbers:
71.Lfunc_begin0:
72	.cv_func_id 0
73	.cv_file	1 "C:\\llvm\\trailing-inlined-function.rs" "A63E3A719BDF505386FDB73BF86EC58591BDAC588181F0E423E724AEEC3E4852" 3
74	.cv_loc	0 1 2 0
75.seh_proc add_numbers
76	subq	$40, %rsp
77	.seh_stackalloc 40
78	.seh_endprologue
79.Ltmp0:
80	.cv_file	2 "/rustc/bc28abf92efc32f8f9312851bf8af38fbd23be42\\library\\core\\src\\option.rs" "7B702FA8D5AAEDC0CCA1EE32F30D5922BC11516B54D592279493A30457F918D9" 3
81	.cv_inline_site_id 1 within 0 inlined_at 1 3 0
82	.cv_loc	1 2 933 0
83	cmpl	$0, (%rcx)
84	je	.LBB0_1
85.Ltmp1:
86	.cv_inline_site_id 2 within 0 inlined_at 1 4 0
87	.cv_loc	2 2 933 0
88	cmpl	$0, (%rdx)
89	je	.LBB0_4
90.Ltmp2:
91	.cv_loc	0 1 5 0
92	movl	4(%rcx), %eax
93.Ltmp3:
94	addl	4(%rdx), %eax
95.Ltmp4:
96	.cv_loc	0 1 6 0
97	addq	$40, %rsp
98	retq
99.LBB0_1:
100.Ltmp5:
101	.cv_loc	1 2 935 0
102	leaq	__unnamed_1(%rip), %rcx
103	leaq	__unnamed_2(%rip), %r8
104.Ltmp6:
105	movl	$43, %edx
106	callq	_ZN4core9panicking5panic17hd083df7b722701afE
107	ud2
108.LBB0_4:
109.Ltmp7:
110	.cv_loc	2 2 935 0
111	leaq	__unnamed_1(%rip), %rcx
112	leaq	__unnamed_3(%rip), %r8
113.Ltmp8:
114	movl	$43, %edx
115	callq	_ZN4core9panicking5panic17hd083df7b722701afE
116	ud2
117.Ltmp9:
118.Lfunc_end0:
119	.seh_endproc
120
121	.section	.rdata,"dr",one_only,__unnamed_1
122__unnamed_1:
123	.ascii	"called `Option::unwrap()` on a `None` value"
124
125	.section	.rdata,"dr",one_only,__unnamed_4
126__unnamed_4:
127	.ascii	"trailing-inlined-function.rs"
128
129	.section	.rdata,"dr",one_only,__unnamed_2
130	.p2align	3, 0x0
131__unnamed_2:
132	.quad	__unnamed_4
133	.asciz	"\034\000\000\000\000\000\000\000\003\000\000\000\020\000\000"
134
135	.section	.rdata,"dr",one_only,__unnamed_3
136	.p2align	3, 0x0
137__unnamed_3:
138	.quad	__unnamed_4
139	.asciz	"\034\000\000\000\000\000\000\000\004\000\000\000\020\000\000"
140
141	.section	.debug$S,"dr"
142	.p2align	2, 0x0
143	.long	4
144	.long	241
145	.long	.Ltmp11-.Ltmp10
146.Ltmp10:
147	.short	.Ltmp13-.Ltmp12
148.Ltmp12:
149	.short	4353
150	.long	0
151	.byte	0
152	.p2align	2, 0x0
153.Ltmp13:
154	.short	.Ltmp15-.Ltmp14
155.Ltmp14:
156	.short	4412
157	.long	21
158	.short	208
159	.short	1
160	.short	73
161	.short	0
162	.short	0
163	.short	17000
164	.short	0
165	.short	0
166	.short	0
167	.asciz	"clang LLVM (rustc version 1.73.0-beta.3 (bc28abf92 2023-08-27))"
168	.p2align	2, 0x0
169.Ltmp15:
170.Ltmp11:
171	.p2align	2, 0x0
172	.long	246
173	.long	.Ltmp17-.Ltmp16
174.Ltmp16:
175	.long	0
176
177
178	.long	4099
179	.cv_filechecksumoffset	2
180	.long	932
181
182
183	.long	4099
184	.cv_filechecksumoffset	2
185	.long	932
186.Ltmp17:
187	.p2align	2, 0x0
188	.section	.debug$S,"dr",associative,add_numbers
189	.p2align	2, 0x0
190	.long	4
191	.long	241
192	.long	.Ltmp19-.Ltmp18
193.Ltmp18:
194	.short	.Ltmp21-.Ltmp20
195.Ltmp20:
196	.short	4423
197	.long	0
198	.long	0
199	.long	0
200	.long	.Lfunc_end0-add_numbers
201	.long	0
202	.long	0
203	.long	4101
204	.secrel32	add_numbers
205	.secidx	add_numbers
206	.byte	128
207	.asciz	"trailing_inlined_function::add_numbers"
208	.p2align	2, 0x0
209.Ltmp21:
210	.short	.Ltmp23-.Ltmp22
211.Ltmp22:
212	.short	4114
213	.long	40
214	.long	0
215	.long	0
216	.long	0
217	.long	0
218	.short	0
219	.long	1138688
220	.p2align	2, 0x0
221.Ltmp23:
222	.short	.Ltmp25-.Ltmp24
223.Ltmp24:
224	.short	4429
225	.long	0
226	.long	0
227	.long	4099
228	.cv_inline_linetable	1 2 932 .Lfunc_begin0 .Lfunc_end0
229	.p2align	2, 0x0
230.Ltmp25:
231	.short	2
232	.short	4430
233	.short	.Ltmp27-.Ltmp26
234.Ltmp26:
235	.short	4429
236	.long	0
237	.long	0
238	.long	4099
239	.cv_inline_linetable	2 2 932 .Lfunc_begin0 .Lfunc_end0
240	.p2align	2, 0x0
241.Ltmp27:
242	.short	2
243	.short	4430
244	.short	2
245	.short	4431
246.Ltmp19:
247	.p2align	2, 0x0
248	.cv_linetable	0, add_numbers, .Lfunc_end0
249	.section	.debug$S,"dr"
250	.cv_filechecksums
251	.cv_stringtable
252	.long	241
253	.long	.Ltmp29-.Ltmp28
254.Ltmp28:
255	.short	.Ltmp31-.Ltmp30
256.Ltmp30:
257	.short	4428
258	.long	4105
259	.p2align	2, 0x0
260.Ltmp31:
261.Ltmp29:
262	.p2align	2, 0x0
263	.section	.debug$T,"dr"
264	.p2align	2, 0x0
265	.long	4
266	.short	0x1e
267	.short	0x1605
268	.long	0x0
269	.asciz	"core::option::Option"
270	.byte	243
271	.byte	242
272	.byte	241
273	.short	0x6
274	.short	0x1201
275	.long	0x0
276	.short	0xe
277	.short	0x1008
278	.long	0x3
279	.byte	0x0
280	.byte	0x0
281	.short	0x0
282	.long	0x1001
283	.short	0x12
284	.short	0x1601
285	.long	0x1000
286	.long	0x1002
287	.asciz	"unwrap"
288	.byte	241
289	.short	0x22
290	.short	0x1605
291	.long	0x0
292	.asciz	"trailing_inlined_function"
293	.byte	242
294	.byte	241
295	.short	0x16
296	.short	0x1601
297	.long	0x1004
298	.long	0x1002
299	.asciz	"add_numbers"
300	.short	0xe
301	.short	0x1605
302	.long	0x0
303	.asciz	"C:\\llvm"
304	.short	0x56
305	.short	0x1605
306	.long	0x0
307	.asciz	"trailing-inlined-function.rs\\@\\trailing_inlined_function.3a6e73a087a7434a-cgu.0"
308	.short	0xa
309	.short	0x1605
310	.long	0x0
311	.byte	0
312	.byte	243
313	.byte	242
314	.byte	241
315	.short	0x1a
316	.short	0x1603
317	.short	0x5
318	.long	0x1006
319	.long	0x0
320	.long	0x1007
321	.long	0x1008
322	.long	0x0
323	.byte	242
324	.byte	241
325