Skip to content

Add additional round-trip fixes and add additional unit tests for greater code coverage - #133188

Open
jkoritzinsky wants to merge 22 commits into
ilasm-fixupsfrom
ilasm-more-tests
Open

Add additional round-trip fixes and add additional unit tests for greater code coverage#133188
jkoritzinsky wants to merge 22 commits into
ilasm-fixupsfrom
ilasm-more-tests

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

Creating a new PR to replace #131509.

jkoritzinskyand others added 19 commits September 3, 2026 11:03
Use the root command option schema for value arity and aliases, and pass ParseResult directly into Program so the schema can be shared with tests.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 69313a92-28b5-4e32-8be8-ea4f6e44a5c8
Use content-based portable PDB IDs for deterministic builds and add in-process coverage for byte-identical PDB output and non-empty PDB ID GUIDs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2fb9f1ef-f721-49e0-bf48-4a7a9458d53a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2fb9f1ef-f721-49e0-bf48-4a7a9458d53a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2fb9f1ef-f721-49e0-bf48-4a7a9458d53a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2fb9f1ef-f721-49e0-bf48-4a7a9458d53a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2fb9f1ef-f721-49e0-bf48-4a7a9458d53a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 106f96fe-da32-41d4-8aa5-7431edb36fc6
…ompiler, it's a compiler that's AOT compiled)
Report oversized generic parameter declarations and constraint owners while preserving native ilasm-compatible wrapped parameter rows in error-tolerant output.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 286b5b04-7d1b-4228-ad6b-dac025ce91a7
Add feature-focused metadata and PE validation tests and fix emitter issues exposed by them.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4307156b-37a7-495d-9af6-fe9174c05b0b
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
… attribute encoding
When an object(...) element in an object[] custom attribute had nested
object() wrappers (e.g. object(object(bool(true)))), VisitSerInit's
object() branch would call WriteCustomAttributeFieldOrPropType on the
inner object() context, producing TaggedObject (0x51) as the element
type code. The .NET metadata decoder does not accept 0x51 as a
FieldOrPropType for object[] elements and throws BadImageFormatException.
Fix VisitObjSeq to fully unwrap any object(...) nesting using a while
loop, so that WriteCustomAttributeFieldOrPropType is always called with
the innermost concrete typed element (bool, int32, string, etc.). This
also makes type-byte handling uniform - always done by VisitObjSeq
rather than split between caller and callee.
Add a regression test CustomAttribute_ObjectArrayWithNestedObjectWrapper
_DecodesProperly that exercises object[](object(bool(true)) object(int32
(42))) and verifies the attribute decodes correctly.
Use comma separators between double-quoted GUID arguments so the tests match the supported .language grammar.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: adc580d5-8f1c-4772-bfc2-7a943aa0959d
Pre-size floating-point sequence builders and transfer their arrays without copying. Handle empty floating-point and string sequences and cover their custom attribute encoding.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: adc580d5-8f1c-4772-bfc2-7a943aa0959d
Allow tests to opt out of managed ilasm round trips while preserving native ilasm coverage, and make the existing all-round-trip exclusion imply the managed-only property.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 286b5b04-7d1b-4228-ad6b-dac025ce91a7
…ely product changes. Make the necessary fixes to the GrammarVisitor model to get these tests passing
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 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.

CopilotAI lite review requested due to automatic review settings September 3, 2026 18:19

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.

Copilot review overview

🟡 Changes recommended

The CLI normalization refactor currently misclassifies value-taking options (using Option.Name vs aliases), and Options introduces a breaking public member rename that should be made compatible or internal.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 High severity · 1 Medium severity · 1 Low severity

New issues introduced by this change (3)
SeverityFinding
High severitysrc/​tools/​ilasm/​src/​ilasm/​NativeCommandLine.cs — optionsWithValues is populated with Option.Name (e.g. "output"), but later checked against…
Medium severitysrc/​tools/​ilasm/​src/​ILAssembler/​Options.cs — Options is a public type and this change replaces the existing public IsDll property with Dll.…
Low severitysrc/​tools/​ilasm/​tests/​ILAssembler.Tests/​CommandLineTests.cs — ModernValueOptions currently includes option.Name in addition to prefixed aliases. In…
What changed in this PR

This PR significantly expands the managed ilasm test suite and adjusts the managed IL assembler, test infrastructure, and CI/configuration to support additional IL round-trip scenarios (including a new managed-ilasm roundtrip), while fixing multiple metadata/PE emission and parsing edge cases uncovered by the added coverage.

Changes:

  • Add broad ILAssembler unit test coverage across metadata emission (typedefs/typerefs/exports/resources/events/properties/fields), parser robustness, preprocessor integration, and options/CLI behavior.
  • Update managed ilasm implementation to improve correctness/compatibility for opcode parsing, vararg/signature handling, PrivateScope naming, PE export/vtable fixup emission, and error-tolerant output behavior.
  • Extend CoreCLR test infrastructure/CI to support managedilasmroundtrip and introduce opt-out markers (ManagedIlasmRoundTripIncompatible) with accompanying documentation.
FileDescription
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypeSignatureTests.csAdds tests for multi-dimensional array local signature shape decoding.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypeReferenceTests.csAdds tests for typeref resolution scopes, mdtoken/.this/.base/.nester, module-scoped typerefs, and typelist parsing.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypedefTests.csAdds typedef alias coverage for fields and custom attributes (including owner-scoped forms).
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypeDefinitionTests.csAdds tests for quoted name segments, class attribute flag behavior, nested types, and interface impl emission.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​SyntaxTests.csAdds corpus-style tests ensuring malformed/truncated inputs report diagnostics instead of throwing.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​SourceDirectiveTests.csStrengthens verification of escape processing and adds portable PDB directive coverage across variants/multi-doc scenarios.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​SecurityTests.csAdds coverage for permissionset syntax variants, emitted DeclSecurity metadata, and error-tolerant behavior.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​PropertyTests.csAdds tests for property attributes/accessors/custom attributes and indexed property signatures.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​PropertyEventTests.csNew tests validating property/event maps and MethodSemantics emission.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​PreprocessorIntegrationTests.csNew integration tests for includes, conditional compilation, and macro expansion across include levels.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​ParameterTests.csAdds tests for parameter attribute syntaxes emitting expected flags.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​NativeExportTests.csNew tests validating PE export directory/stub emission and machine-specific stub prefixes.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​ModuleTests.csAdds tests for .file metadata/resources, module refs, bare .module, and global method/module attribute + PDB emission.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​ManifestResourceTests.csNew tests for embedded/file/assembly-backed manifest resources and deterministic/error-tolerant behavior.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​ILAssembler.Tests.csprojAdds System.CommandLine dependency and links IlasmRootCommand.cs for CLI parsing tests.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​FunctionPointerTests.csSwitches to signature decoding assertions; adds vararg fnptr sentinel coverage.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​FieldTests.csAdds tests for trailing custom attribute binding and field attribute flag/null constant emission.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​ExportedTypeTests.csAdds coverage for ExportedType attributes/implementations/custom attributes and TypeDefId emission.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​ExceptionHandlingTests.csAdds extensive EH region tests (offset-based, label-based, ordering, filter/fault/finally/catch).
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​EventTests.csAdds event accessor/attribute/other/custom-attr metadata tests and nil-type behavior.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​DocumentCompilerTests.csNew tests ensuring diagnostics have correct document paths and parser errors don’t leak scopes across documents.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​DocumentCompilerTestHelpers.csAdds shared PEReader compile helper, token operand extraction, and metadata signature decoding provider.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​DataTests.csAdds coverage for data directives (typed bytes, repeats, large bytearrays, float literals, syntax variants, error isolation).
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​CompilerOptionsTests.csNew tests verifying Options-driven PE/metadata behavior, debug attributes, deterministic output, keyfile handling, and error-tolerant output.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​CommandLineTests.csUpdates modern option corpus generation to reflect IlasmRootCommand options (CLI normalization tests).
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​AssemblyTests.csUpdates Options property name usage and adds additional assembly reference/identity/attribute parsing tests.
src/​tools/​ilasm/​src/​ILAssembler/​VTableExportPEBuilder.csFixes COR header vtable directory offset and improves vtable/export directory emission logic (including ordinal gaps).
src/​tools/​ilasm/​src/​ILAssembler/​PreprocessedTokenSource.csFixes include-stack EOF handling to avoid incorrectly popping the entry source.
src/​tools/​ilasm/​src/​ILAssembler/​Options.csRenames the DLL output option property (public surface) and updates option model.
src/​tools/​ilasm/​src/​ILAssembler/​NameHelpers.csAdds helper to normalize PrivateScope metadata names (strip $PST + token suffix).
src/​tools/​ilasm/​src/​ILAssembler/​MetadataExtensions.csAdds ILOpCode.Unused support used by opcode parsing.
src/​tools/​ilasm/​src/​ILAssembler/​gen/​CIL.g4Fixes token spelling and extends grammar for dotted names, mdtoken forms, unsigned native types, permissionset syntax, and opcode set.
src/​tools/​ilasm/​src/​ILAssembler/​EntityRegistry.csUpdates metadata emission behavior (PrivateScope naming, method body encoding heuristics, methodimpl owner, vararg sig rewriting, error-tolerant metadata row preservation).
src/​tools/​ilasm/​src/​ILAssembler/​DocumentCompiler.csEnhances parser error context propagation so the visitor can avoid leaking state across erroneous contexts.
src/​tools/​ilasm/​src/​ILAssembler/​Diagnostic.csAdds a new diagnostic ID/message for constraint owner out-of-range scenarios.
src/​tools/​ilasm/​src/​ilasm/​Program.csRefactors CLI handling to use ParseResult explicitly and wires Normalize() with a single command instance.
src/​tools/​ilasm/​src/​ilasm/​NativeCommandLine.csRefactors CLI normalization to derive supported options from IlasmRootCommand.
src/​tools/​ilasm/​src/​ilasm/​IlasmRootCommand.csRemoves embedded SetAction wiring (now configured from Program.Main).
src/​tools/​ilasm/​src/​ilasm/​ilasm.csprojInlines NativeAOT runtime settings previously imported from AotCompilerCommon.props.
src/​tests/​Loader/​classloader/​regressions/​dev10_403582/​gentype.ilprojMarks the project as incompatible with managed ilasm round-trip.
src/​tests/​Loader/​classloader/​regressions/​dev10_403582/​genmeth.ilprojMarks the project incompatible with IL round-trip (and documents ildasm crash).
src/​tests/​Directory.Build.targetsEmits marker files for IlasmRoundTripIncompatible and ManagedIlasmRoundTripIncompatible.
src/​tests/​Common/​CLRTest.Jit.targetsAdds marker-file based skipping and introduces managed-ilasm round-trip selection logic.
src/​tests/​Common/​CLRTest.Execute.targetsMakes IlasmRoundTripIncompatible imply ManagedIlasmRoundTripIncompatible.
src/​tests/​Common/​CLRTest.Execute.Batch.targetsAdds managed-ilasm-only skip logic for batch execution wrapper.
src/​tests/​Common/​CLRTest.Execute.Bash.targetsAdds managed-ilasm-only skip logic for bash execution wrapper.
eng/​pipelines/​common/​templates/​runtimes/​run-test-job.ymlAdds managedilasmroundtrip scenario to ilasm test group.
docs/​workflow/​testing/​coreclr/​test-configuration.mdDocuments ManagedIlasmRoundTripIncompatible and the implication behavior.
docs/​workflow/​testing/​coreclr/​requiresprocessisolation.mdUpdates guidance for IL round-trip incompatibility properties and isolation requirements.
docs/​workflow/​ci/​disabling-tests.mdDocuments disabling managed vs all ilasm round-trip and notes merged-runner behavior.

Comment threadsrc/tools/ilasm/src/ilasm/NativeCommandLine.cs Outdated
Comment on lines +68 to +72
/// <summary>
/// Produce a DLL image instead of an executable.
/// </summary>
public bool Dll { get; set; }

Comment threadsrc/tools/ilasm/tests/ILAssembler.Tests/CommandLineTests.cs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 806a996a-9fcc-42b7-a902-cac954582b24
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 806a996a-9fcc-42b7-a902-cac954582b24
CopilotAI review requested due to automatic review settings September 4, 2026 15:28

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.

Copilot review overview

🟡 Changes recommended

The new fat-header forcing logic in EntityRegistry can cause .maxstack-only methods (without .zeroinit) to emit InitLocals, altering semantics/metadata in a way that should be corrected or explicitly justified and locked in with tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 2 Medium severity

New issues introduced by this change (1)
SeverityFinding
Medium severitysrc/​tools/​ilasm/​src/​ILAssembler/​EntityRegistry.csforceFatHeader triggers when methodDef.MaxStack &lt; 8 (i.e., .maxstack was explicitly…
Pre-existing issues (1)
SeverityFinding
Medium severitysrc/​tools/​ilasm/​src/​ILAssembler/​Options.cs — Options is a public type and this change replaces the existing public IsDll property with Dll.… View comment
Issues resolved since last review (2)
SeverityFinding
Low severitysrc/​tools/​ilasm/​tests/​ILAssembler.Tests/​CommandLineTests.cs — ModernValueOptions currently includes option.Name in addition to prefixed aliases. In… View resolved comment
High severitysrc/​tools/​ilasm/​src/​ilasm/​NativeCommandLine.cs — optionsWithValues is populated with Option.Name (e.g. "output"), but later checked against… View resolved comment

Comment on lines 374 to +394
StandaloneSignatureHandle localsSigHandle = methodDef.LocalsSignature is not null
? (StandaloneSignatureHandle)methodDef.LocalsSignature.Handle
: default;
bool forceFatHeader = (methodDef.MaxStack < 8 || methodDef.BodyAttributes.HasFlag(MethodBodyAttributes.InitLocals))
&& methodDef.MethodBody.CodeBuilder.Count < 64
&& localsSigHandle.IsNil
&& methodDef.ExceptionRegions.Count == 0;
try
{
MethodBodyAttributes encodingAttributes = methodDef.BodyAttributes;
if (forceFatHeader)
{
encodingAttributes |= MethodBodyAttributes.InitLocals;
}

bodyOffset = bodyStreamEncoder.AddMethodBody(
methodDef.MethodBody,
methodDef.MaxStack,
localsSigHandle,
methodDef.BodyAttributes);
encodingAttributes,
methodDef.HasDynamicStackAllocation || forceFatHeader);
jkoritzinsky added a commit that referenced this pull request Sep 4, 2026
…ing. (#133202)
The existing implementation was leading to file lock conflicts on
#133188 and other managed ILASM PRs.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants

@jkoritzinsky