Skip to content

Handle ILLink origins before first sequence point - #129869

Merged
sbomer merged 2 commits into
dotnet:mainfrom
sbomer:runtime-illink-crash
Jun 26, 2026
Merged

Handle ILLink origins before first sequence point#129869
sbomer merged 2 commits into
dotnet:mainfrom
sbomer:runtime-illink-crash

Conversation

@sbomer

@sbomersbomer commented Jun 25, 2026

Copy link
Copy Markdown
Member

Fixes#129562.

MessageOrigin.ToString() assumed that every diagnostic IL offset has at least one PDB sequence point at or before that offset. Rewritten/generated IL can put a warning origin before the first sequence point, which made Last() throw while ILLink flushed cached warnings.

This changes the lookup to tolerate that shape by falling back to the first available sequence point, and adds a focused regression test that round-trips a Cecil-generated assembly/PDB to reproduce the real offset behavior.

This content was created with assistance from AI.

Avoid throwing while formatting diagnostics whose IL offset precedes the first available PDB sequence point. Fall back to the first sequence point and cover the case with a focused MessageContainer test.
Assisted-by: Copilot:gpt-5.5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 25, 2026 20:42
@github-actionsgithub-actionsBot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jun 25, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the linkable-framework Issues associated with delivering a linker friendly framework label Jun 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates ILLink’s diagnostic origin formatting to handle method IL offsets that occur before the first available PDB sequence point, preventing MessageOrigin.ToString() from throwing when generating MSBuild-formatted messages. It also adds a regression test that constructs and round-trips a Cecil-generated assembly + Portable PDB to reproduce the offset shape.

Changes:

  • Make MessageOrigin.ToString() tolerate “origin before first sequence point” by falling back to the first available sequence point instead of throwing.
  • Add a targeted xUnit regression test that emits a Portable PDB where the only sequence point is after the first IL instruction, then verifies ToMSBuildString() output.
Show a summary per file
FileDescription
src/tools/illink/src/linker/Linker/MessageOrigin.csAdjusts sequence point selection logic to avoid Last() throwing when no sequence point exists at/before the IL offset.
src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.csAdds a Cecil-based regression test covering an origin IL offset occurring before the first sequence point.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment threadsrc/tools/illink/src/linker/Linker/MessageOrigin.cs Outdated
Keep the existing LINQ-based sequence point lookup but use LastOrDefault so diagnostics whose IL offset precedes the first sequence point fall back to the tool name instead of throwing, matching ILC behavior.
Assisted-by: Copilot:gpt-5.5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sbomer
sbomer requested a review from a teamJune 26, 2026 17:24
@sbomer
sbomer merged commit 207ffd1 into dotnet:mainJun 26, 2026
87 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview7 milestone Jun 28, 2026
@sbomer
sbomer deleted the runtime-illink-crash branch June 30, 2026 22:53
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Fixes#129562.
`MessageOrigin.ToString()` assumed that every diagnostic IL offset has
at least one PDB sequence point at or before that offset.
Rewritten/generated IL can put a warning origin before the first
sequence point, which made `Last()` throw while ILLink flushed cached
warnings.
This changes the lookup to tolerate that shape by falling back to the
first available sequence point, and adds a focused regression test that
round-trips a Cecil-generated assembly/PDB to reproduce the real offset
behavior.
*This content was created with assistance from AI.*
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 31, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzerslinkable-frameworkIssues associated with delivering a linker friendly framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[area-Tools-ILLink]: Trimmer warnings crash the build

3 participants

@sbomer@jtschuster