Don't assert decompiled local types match the signature - #3836
Merged
Conversation
DebugInfoGenerator asserted that every local variable's decompiled type is equivalent to the metadata local-signature type at its slot. That holds at IL-read time but not afterwards: variable splitting gives one slot several typed variables, pinned-region locals are modeled as pointers (int* vs int& pinned), and generic-context type-parameter identity differs. The assertion therefore aborted PDB generation (Debug builds) for ordinary inputs such as any method with a fixed statement. The type is never written to the PDB - only the slot index and name are - so the mismatch cannot affect the debugging experience. The slot index, the only emitted value, is correct by construction: it is the IL ldloc/stloc operand, sourced from the signature slot when the variable is created and copied verbatim by SplitVariables; it is never reassigned. Keep only the index-bound check and document why the type is not verified. Assisted-by: Claude:claude-opus-4-8:Claude Code
siegfriedpammer
force-pushed
the
fix-localsig-assert
branch
from
June 27, 2026 14:09
5e3067a to
f99242c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DebugInfoGenerator.HandleMethodBodyasserted, for every local variable, that its decompiled type is equivalent to the metadata local-signature type at the same slot:This aborts portable-PDB generation (Debug builds) for ordinary inputs — e.g. any method containing a
fixedstatement, and async state machines — surfaced while generating PDBs for real assemblies such asSystem.Net.Requests.dll.Why the type check is wrong
The type equivalence holds when the variables are first read from IL, but not afterwards:
int*), while the signature types the slot asint& pinned.ReadOnlySpan<``0>vsReadOnlySpan<0>` in local functions / iterators).Empirically, ~32% of CoreLib's qualifying locals mismatch across these classes; neither a size nor an
IsCompatibleTypeForMemoryAccesscomparison covers them.Why it cannot affect debugging
AddLocalVariablewrites only the slot index and name to the PDB — never the type, which the debugger reads from the metadata signature directly. And the slot index is correct by construction: it is the ILldloc/stlocoperand, assigned from the signature slot when the variable is created (ILReader.InitLocalVariables) and copied verbatim bySplitVariables;ILVariable.Indexis never reassigned. A wrong index is ruled out structurally.Fix
Drop the type-equivalence check; keep only the (trivially-true, documented) index bound as a guard against a future regression in index assignment.
Test
Adds
TestCases/PdbGen/PinnedLocalSlot.il— a minimalfixedstatement whose pinned local isint& pinnedin metadata butint*after decompilation — and aPdbGenerationTestRunner.PinnedLocalSlottest that runsDebugInfoGeneratorover it and asserts it does not throw. Fails (asserts) before the fix, passes after; full PdbGen fixture stays green.🤖 Generated with Claude Code