Skip to content

Add runtime-async varargs testcase and treat vararg Task-returning methods as normal methods#130509

Draft
VSadov with Copilot wants to merge 2 commits into
mainfrom
copilot/add-testcase-task-returning-methods
Draft

Add runtime-async varargs testcase and treat vararg Task-returning methods as normal methods#130509
VSadov with Copilot wants to merge 2 commits into
mainfrom
copilot/add-testcase-task-returning-methods

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

__arglist (vararg calling convention) is an unsupported combination with runtime-async. Previously an async MethodImpl vararg method could produce a broken async thunk (crash/UB), and there was no coverage for vararg Task/ValueTask methods. The goal is "don't crash on scenarios that used to work."

Runtime change (src/coreclr/vm/methodtablebuilder.cpp)

In EnumerateClassMethods, before async-variant creation, classify vararg Task/ValueTask-returning methods deterministically:

  • Ordinary (non-async) vararg Task/ValueTask method → re-classified as NormalMethod, so no async variant is generated and it behaves exactly as before.
  • async MethodImpl vararg method → throws IDS_EE_VARARG_NOT_SUPPORTED (TypeLoadException) at type load instead of emitting a broken thunk.
// Vararg methods are not allowed to be marked MethodImpl.Async
// and even when they return Tasks they are still treated as NormalMethod.
if (returnKind != MethodReturnKind::NormalMethod)
{
    if (MetaSig::IsVarArg(Signature(pMemberSignature, cMemberSignature)))
    {
        if (IsMiAsync(dwImplFlags))
            BuildMethodTableThrowException(IDS_EE_VARARG_NOT_SUPPORTED);
        else
            returnKind = MethodReturnKind::NormalMethod;
    }
}

Test (src/tests/async/varargs/varargs.il + varargs.ilproj)

Authored in IL because Roslyn rejects __arglist in async methods under runtime-async (CS9328).

  • Ordinary vararg Task/ValueTask methods (using ArgIterator): validated via direct call and via await from a runtime-async wrapper.
  • async vararg Task/ValueTask methods: asserting the declaring type fails to load with TypeLoadException.
  • Vararg call sites are isolated in dedicated helpers and each Fact is guarded with OperatingSystem.IsWindows(), since managed varargs are Windows-only (compFeatureVarArg, src/coreclr/jit/target.h); non-Windows platforms skip without jitting a vararg instruction.

Validation notes

The positive vararg paths cannot be exercised on Linux (managed __arglist is unsupported off-Windows — the JIT emits BADCODE), hence the Windows runtime gating; those paths depend on Windows CI for full validation. The runtime fix compiles cleanly.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-threading-tasks
See info in area-owners.md if you want to be subscribed.

…ormal

Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 10, 2026 18:44
Copilot AI changed the title [WIP] Add testcase for Task-returning methods using __arglist Add runtime-async varargs testcase and treat vararg Task-returning methods as normal methods Jul 10, 2026
Copilot AI requested a review from VSadov July 10, 2026 18:44
Copilot AI temporarily deployed to copilot-pat-pool July 10, 2026 22:43 Inactive
Copilot AI temporarily deployed to copilot-pat-pool July 10, 2026 22:44 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RuntimeAsync] Add a testcase for Task-returning methods that use __arglst

2 participants