Skip to content

Fix JIT assert resolving to C runtime assert after jitshared introduction#124977

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-jit-assert-issue
Draft

Fix JIT assert resolving to C runtime assert after jitshared introduction#124977
Copilot wants to merge 3 commits intomainfrom
copilot/fix-jit-assert-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

After PR #123830 introduced the jitshared/ directory, assert in JIT (and interpreter) code was silently falling through to the C runtime's assert, causing dialog popups on assertion failures instead of using assertAbort.

Root Cause

The JIT sets up assert → assertAbort in host.h, which alloc.h includes before the jitshared headers. However, three files in jitshared/ included <assert.h>/<cassert> directly, which unconditionally redefined assert back to the C runtime version — clobbering the JIT's custom handler:

  • arenaallocator.h#include <assert.h>
  • compallocator.h#include <assert.h>
  • histogram.cpp#include <cassert>

The interpreter had a related issue: histogram.cpp (compiled as part of the interpreter without a PCH) had no assert definition at all after removing #include <cassert>, since the interpreter doesn't use a precompiled header to supply it.

Changes

  • jitshared/arenaallocator.h, jitshared/compallocator.h: Remove #include <assert.h>. The correct assert is now provided by jitassert.h via jitshared.h.
  • jitshared/histogram.cpp: Remove #include <cassert>jitassert.h (included via histogram.h) now supplies the correct definition.
  • jitshared/jitassert.h (new): Shared header that declares assertAbort (with ANALYZER_NORETURN) and defines assert to use it in DEBUG builds, or ((void)0) in release builds. This is the single source of truth for the assert API shared between JIT and interpreter.
  • jitshared/jitshared.h: Include jitassert.h so all jitshared code that goes through jitshared.h automatically gets the correct assert.
  • jitshared/histogram.h: Include jitassert.h directly, so histogram.cpp in the interpreter build (which doesn't go through jitshared.h) also gets the correct assert.
  • interpreter/interpreter.h: Reverted to original include order (compiler.h before the assertAbort block) — jitshared code now correctly gets assert from jitassert.h via the jitshared include chain, making the ordering no longer relevant.
Original prompt

This section details on the original issue you should resolve

<issue_title>JIT assert resolves to C runtime assert</issue_title>
<issue_description>It seems after #123830 assert in the JIT ends up calling into the C runtime's assert, popping open a dialog when it fails.

cc @dotnet/jit-contrib @davidwrighton </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 27, 2026
@dotnet-policy-service
Copy link
Contributor

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

…m jitshared headers

Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix JIT assert to prevent C runtime dialog Fix JIT assert resolving to C runtime assert after jitshared introduction Feb 27, 2026
@davidwrighton
Copy link
Member

@copilot, the interpreter is now missing a definition for assert. Could you fix that by moving the jit assert API into jitshared?

… interpreter

Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot, the interpreter is now missing a definition for assert. Could you fix that by moving the jit assert API into jitshared?

Done in commit 40fb666. Created src/coreclr/jitshared/jitassert.h that declares assertAbort and defines the assert macro, then included it from jitshared.h (for all jitshared code going through that header) and from histogram.h (for histogram.cpp in the interpreter build, which doesn't go through jitshared.h). Also reverted interpreter.h to its original include order — jitshared code now correctly gets assert from jitassert.h. Verified both JIT and interpreter (including histogram.cpp) compile cleanly in Debug mode.

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

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT assert resolves to C runtime assert

2 participants