rust/compiler/rustc_codegen_gcc/src
bors 154ae32a55 Auto merge of #114643 - dpaoliello:inlinedebuginfo, r=wesleywiser
Use the same DISubprogram for each instance of the same inlined function within a caller

# Issue Details:
The call to `panic` within a function like `Option::unwrap` is translated to LLVM as a `tail call` (as it will never return), when multiple calls to the same function like this is inlined LLVM will notice the common `tail call` block (i.e., loading the same panic string + location info and then calling `panic`) and merge them together.

When merging these instructions together, LLVM will also attempt to merge the debug locations as well, but this fails (i.e., debug info is dropped) as Rust emits a new `DISubprogram` at each inline site thus LLVM doesn't recognize that these are actually the same function and so thinks that there isn't a common debug location.

As an example of this when building for x86_64 Windows (note the lack of `.cv_loc` before the call to `panic`, thus it will be attributed to the same line at the `addq` instruction):

```
	.cv_loc	0 1 23 0                        # src\lib.rs:23:0
	addq	$40, %rsp
	retq
	leaq	.Lalloc_f570dea0a53168780ce9a91e67646421(%rip), %rcx
	leaq	.Lalloc_629ace53b7e5b76aaa810d549cc84ea3(%rip), %r8
	movl	$43, %edx
	callq	_ZN4core9panicking5panic17h12e60b9063f6dee8E
	int3
```

# Fix Details:
Cache the `DISubprogram` emitted for each inlined function instance within a caller so that this can be reused if that instance is encountered again, this also requires caching the `DILexicalBlock` and `DIVariable` objects to avoid creating duplicates.

After this change the above assembly now looks like:

```
	.cv_loc	0 1 23 0                        # src\lib.rs:23:0
	addq	$40, %rsp
	retq
	.cv_inline_site_id 5 within 0 inlined_at 1 0 0
	.cv_inline_site_id 6 within 5 inlined_at 1 12 0
	.cv_loc	6 2 935 0                       # library\core\src\option.rs:935:0
	leaq	.Lalloc_5f55955de67e57c79064b537689facea(%rip), %rcx
	leaq	.Lalloc_e741d4de8cb5801e1fd7a6c6795c1559(%rip), %r8
	movl	$43, %edx
	callq	_ZN4core9panicking5panic17hde1558f32d5b1c04E
	int3
```
2023-08-22 20:15:29 +00:00
..
back Merge commit '08a6d6e16b' into sync-cg_gcc-2023-03-04 2023-03-05 12:03:19 -05:00
intrinsic Apply suggestions from code review 2023-08-06 15:47:40 -07:00
abi.rs Merge apply_attrs_callsite into call and invoke 2022-10-01 17:01:31 +00:00
allocator.rs Generate better function argument names in global_allocator expansion 2023-08-06 07:36:05 -07:00
archive.rs Rewrite LLVM's archive writer in Rust 2022-11-26 19:35:32 +00:00
asm.rs Auto merge of #114467 - Amanieu:asm-unstable-features, r=davidtwco 2023-08-15 11:59:02 +00:00
attributes.rs Merge commit '1bbee3e217' into sync-cg_gcc-2023-06-19 2023-06-19 18:51:02 -04:00
base.rs Introduce MonoItemData. 2023-07-17 08:44:48 +10:00
builder.rs cg_ssa: remove pointee types and pointercast/bitcast-of-ptr 2023-07-29 13:18:20 -04:00
callee.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
common.rs cg_ssa: remove pointee types and pointercast/bitcast-of-ptr 2023-07-29 13:18:20 -04:00
consts.rs Merge commit '1bbee3e217' into sync-cg_gcc-2023-06-19 2023-06-19 18:51:02 -04:00
context.rs Fix ICE failed to get layout for ReferencesError 2023-08-05 01:38:14 +08:00
coverageinfo.rs Remove trait CoverageInfoMethods, since non-LLVM backends don't need it 2023-07-05 20:40:40 +10:00
debuginfo.rs Use the same DISubprogram for each instance of the same inlined function within the caller 2023-08-11 10:21:52 -07:00
declare.rs Merge commit '1bbee3e217' into sync-cg_gcc-2023-06-19 2023-06-19 18:51:02 -04:00
errors.rs UPDATE - replace expected_simd error with one from codegen_ssa 2023-07-20 00:20:00 -04:00
int.rs Merge commit '08a6d6e16b' into sync-cg_gcc-2023-03-04 2023-03-05 12:03:19 -05:00
lib.rs Use standard Rust capitalization rules for names containing "LTO". 2023-07-31 16:21:02 +10:00
mono_item.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
type_.rs cg_ssa: remove pointee types and pointercast/bitcast-of-ptr 2023-07-29 13:18:20 -04:00
type_of.rs Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk" 2023-07-21 22:35:57 -07:00