Fix XA3006: Sanitize whitespace-only parameter names in marshal methods LLVM IR generation#10835
Conversation
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
|
@copilot can you add a test that reproduces the original problem? |
…tion and fix LlvmIrFunction constructor Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Added regression tests in
I also fixed the root cause in |
There was a problem hiding this comment.
Pull request overview
Fixes marshal-methods LLVM IR generation failures (XA3006) when managed method parameters have whitespace-only names, by sanitizing/normalizing such names so LLVM IR always receives valid parameter identifiers.
Changes:
- Treat whitespace-only parameter names as invalid and auto-assign numeric parameter names in
LlvmIrFunction. - Normalize whitespace-only metadata parameter names to
nullin marshal-methods native assembly generation. - Add regression tests covering invalid/unnamed parameter names.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs | Normalizes whitespace-only managed parameter names to null before creating LLVM IR parameters. |
| src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/LlvmIrFunction.cs | Changes name validation to IsNullOrWhiteSpace so whitespace-only names get numeric identifiers. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/LlvmIrGeneratorTests.cs | Adds tests for invalid parameter names and generated IR output. |
| /// <summary> | ||
| /// Regression test for https://github.com/dotnet/android/issues/10086 | ||
| /// |
There was a problem hiding this comment.
| public void GeneratedIR_FunctionWithUnnamedParameter_ProducesValidOutput () | ||
| { | ||
| var parameters = new List<LlvmIrFunctionParameter> { | ||
| new LlvmIrFunctionParameter (typeof (IntPtr), "env"), | ||
| new LlvmIrFunctionParameter (typeof (IntPtr), "klass"), | ||
| new LlvmIrFunctionParameter (typeof (IntPtr), null), // unnamed parameter | ||
| }; |
There was a problem hiding this comment.
This test is intended to verify generated IR is valid when a parameter name is whitespace-only, but it currently uses a null parameter name. A null name would have been handled even before this fix, so the test won’t fail on the original bug. Consider changing/add test cases to pass whitespace-only names (e.g., " ", "\t") and assert the output does not contain invalid patterns like "% )" / "%\t)" in the function signature.
|
@copilot apply changes based on the comments in this thread |
…ames in end-to-end test Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Applied both changes in
|
jonathanpeppers
left a comment
There was a problem hiding this comment.
MAUI Integration Lane is only failure, and it's broken for unrelated reasons right now.
Fix for XA3006: Could not compile native assembly file - Invalid parameter name in LLVM IR
Problem
When a managed method has a parameter without a name (or with an empty/whitespace name), the marshal methods generator creates invalid LLVM IR code like:
Note the
% )with no parameter name (or just whitespace), which causes LLVM'sllccompiler to fail with: "expected ')' at end of argument list"Root Cause
In
LlvmIrFunction.cs, the constructor checksString.IsNullOrEmptyto determine if a parameter needs a numeric name assignment. However, whitespace-only names like" "pass this check, resulting in invalid LLVM IR output (ptr noundef %).Changes Made
LlvmIrFunction.cs: ChangedString.IsNullOrEmptytoString.IsNullOrWhiteSpacein the constructor's parameter name validation, so whitespace-only names are properly caught and assigned numeric names.MarshalMethodsNativeAssemblyGenerator.cs: Added defensive check usingString.IsNullOrWhiteSpacewhen reading parameter names from managed method metadata, normalizing invalid names tonullbefore creatingLlvmIrFunctionParameterinstances.LlvmIrGeneratorTests.cs: Added regression tests that:LlvmIrFunctionassigns numeric names to parameters with null, empty, space-only, multi-space, and tab-only names% )or%\t)patterns) when parameters have whitespace-only namesTasks
Original prompt
This section details on the original issue you should resolve
<issue_title>Could not compile native assembly file: marshal_methods.arm64-v8a.ll</issue_title>
<issue_description>### Android framework version
net10.0-android (Preview)
Affected platform version
VS2026 - December 2025 Feature Update - V18.1.1
Description
When compiling or publishing Android the output shows the following error:
As i have no idea where this is coming from i have also no possibility to create a small project which contains the same error. Tried building the project on 3 different development workstations and all gave the same result.
Steps to Reproduce
As i have no idea where this is coming from i have also no possibility to create a small project which contains the same error. Tried building the project on 3 different development workstations and all gave the same result.
Did you find any workaround?
msbuild.binlog.zip
Relevant log output
(0,1): error JAVA0000: Error in C:\Use...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.