Skip to content

Fix nested managed ilasm preprocessor conditionals - #137441

Merged
jkoritzinsky merged 2 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-nested-preprocessor-fix
Nov 14, 2026
Merged

jkoritzinsky merged 2 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-nested-preprocessor-fix

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

Summary

  • Process preprocessor directives immediately following conditional transitions, and restore the active conditional stack when leaving a block.
  • Recognize nested #ifndef blocks while skipping disabled input.
  • Add regression coverage for nested ARM64, X64, and X86 macro selection and adjacent conditional directives.

Validation

  • .\dotnet.cmd build src\tools\ilasm\src\ilasm\ilasm_inbuild.csproj -c Debug -p:NuGetAudit=false -v:q -nologo: passed.
  • .\dotnet.cmd test src\tools\ilasm\tests\ILAssembler.Tests -f net11.0 -p:NuGetAudit=false --filter "FullyQualifiedName~PreprocessedTokenSource" -v:q -nologo: passed (34 tests).
  • The following managed ilasm commands passed for the actual VTableFixups inputs. Inspection of the generated PE files showed four 32-bit fixups for X86 and four 64-bit fixups for X64:
    $o = "$env:TEMP\vtf"
    $d = 'src\tests\Loader\classloader\MixedMode'
    $il = 'artifacts\bin\ilasm_inbuild\Debug\ilasm.dll'
    .\dotnet.cmd exec $il -dll -quiet "-output=$o\VTableFixupsX86.dll" "$d\VTableFixups.il"
    .\dotnet.cmd exec $il -dll -quiet -PE64 -X64 "-output=$o\VTableFixupsX64.dll" "$d\X64.il" "$d\VTableFixups.il"
  • MixedMode runtime tests were not run.

Resolves #137424

Note

This PR description was generated with GitHub Copilot.

Process directives after conditional transitions, balance active conditional state, and track nested ifndef blocks while skipping disabled input. Add regression coverage for nested macro selection and conditional transitions.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the nested-conditional preprocessor changes.

No open issues 🎉

What changed in this PR

This PR fixes nested conditional handling in the managed IL assembler’s preprocessor, ensuring the selected branches and macros are processed correctly.

Changes:

  • Restore the active conditional stack when leaving a block and process adjacent directives immediately.
  • Recognize nested #ifndef directives while skipping disabled input.
  • Add regression tests for architecture-dependent macro selection, disabled nested branches, and conditional-state restoration.
File Description
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​PreprocessedTokenSourceTests.cs Adds parameterized coverage for nested and adjacent conditionals.
src/​tools/​ilasm/​src/​ILAssembler/​PreprocessedTokenSource.cs Fixes conditional-stack restoration, directive processing, and nested #ifndef recognition.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Managed ilasm fails to assemble VTableFixups.il with nested preprocessor conditionals

3 participants