diff options
| author | bors <bors@rust-lang.org> | 2024-11-20 02:10:50 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-11-20 02:10:50 +0000 | 
| commit | bcfea1f8d253fd43eab36832fa601d192ac603d5 (patch) | |
| tree | 8e64f5f91ed45c616ccdb569e58d9f78a820f18a /compiler/rustc_codegen_ssa/src | |
| parent | 875df370be806c837f58abb638329905e969ace4 (diff) | |
| parent | f5b023bd9cf43803a6d39b101c54a98cb7e7da7c (diff) | |
| download | rust-bcfea1f8d253fd43eab36832fa601d192ac603d5.tar.gz rust-bcfea1f8d253fd43eab36832fa601d192ac603d5.zip | |
Auto merge of #133194 - khuey:master, r=jieyouxu
Drop debug info instead of panicking if we exceed LLVM's capability to represent it Recapping a bit of history here: In #128861 I made debug info correctly represent parameters to inline functions by removing a fake lexical block that had been inserted to suppress LLVM assertions and by deduplicating those parameters. LLVM, however, expects to see a single parameter _with distinct locations_, particularly distinct inlinedAt values on the DILocations. This generally worked because no matter how deep the chain of inlines it takes two different call sites in the original function to result in the same function being present multiple times, and a function call requires a non-zero number of characters, but macros threw a wrench in that in #131944. At the time I thought the issue there was limited to proc-macros, where an arbitrary amount of code can be generated at a single point in the source text. In #132613 I added discriminators to DILocations that would otherwise be the same to repair #131944[^1]. This works, but LLVM's capacity for discriminators is not infinite (LLVM actually only allocates 12 bits for this internally). At the time I thought it would be very rare for anyone to hit the limit, but #132900 proved me wrong. In the relatively-minimized test case it also became clear to me that the issue affects regular macros too, because the call to the inlined function will (without collapse_debuginfo on the macro) be attributed to the (repeated, if the macro is used more than once) textual callsite in the macro definition. This PR fixes the panic by dropping debug info when we exceed LLVM's maximum discriminator value. There's also a preceding commit for a related but distinct issue: macros that use collapse_debuginfo should in fact have their inlinedAts collapsed to the macro callsite and thus not need discriminators at all (and not panic/warn accordingly when the discriminator limit is exhausted). Fixes #132900 r? `@jieyouxu` [^1]: Editor's note: `fix` is a magic keyword in PR description that apparently will close the linked issue (it's closed already in this case, but still).
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/debuginfo.rs | 6 | 
1 files changed, 4 insertions, 2 deletions
| diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 21d20475408..d4d7f16db55 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -20,7 +20,9 @@ use crate::traits::*; pub struct FunctionDebugContext<'tcx, S, L> { /// Maps from source code to the corresponding debug info scope. - pub scopes: IndexVec<mir::SourceScope, DebugScope<S, L>>, + /// May be None if the backend is not capable of representing the scope for + /// some reason. + pub scopes: IndexVec<mir::SourceScope, Option<DebugScope<S, L>>>, /// Maps from an inlined function to its debug info declaration. pub inlined_function_scopes: FxHashMap<Instance<'tcx>, S>, @@ -231,7 +233,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &self, source_info: mir::SourceInfo, ) -> Option<(Bx::DIScope, Option<Bx::DILocation>, Span)> { - let scope = &self.debug_context.as_ref()?.scopes[source_info.scope]; + let scope = &self.debug_context.as_ref()?.scopes[source_info.scope]?; let span = hygiene::walk_chain_collapsed(source_info.span, self.mir.span); Some((scope.adjust_dbg_scope_for_span(self.cx, span), scope.inlined_at, span)) } | 
