Skip to content

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

Merged
jakobbotsch merged 3 commits intomainfrom
copilot/fix-jit-assert-issue
Mar 4, 2026
Merged

Fix JIT assert resolving to C runtime assert after jitshared introduction#124977
jakobbotsch merged 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.

@jakobbotsch
Copy link
Member

@davidwrighton what is missing to land this? It would be nice to get this in since it is affecting our ability to test in CI and evaluate our changes locally.

@davidwrighton
Copy link
Member

@jakobbotsch I need someone to review this. If you do, please just merge it, as my review indicates its good.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an assert-macro regression introduced by the jitshared/ split so JIT/interpreter assertions consistently route to the CoreCLR assertAbort handler (instead of falling back to the C runtime assert).

Changes:

  • Introduces jitshared/jitassert.h as the shared source of truth for assertassertAbort.
  • Ensures jitshared consumers get the correct assert macro via jitshared.h (and histogram.h for interpreter builds without the jitshared include chain).
  • Removes direct <assert.h> / <cassert> includes in jitshared code that were clobbering the custom assert mapping.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/jitshared/jitshared.h Includes jitassert.h so jitshared compilation units get the shared assert behavior by default.
src/coreclr/jitshared/jitassert.h New shared assert definition/declaration that maps assert to assertAbort in DEBUG.
src/coreclr/jitshared/histogram.h Includes jitassert.h directly to support interpreter builds that don’t include jitshared.h.
src/coreclr/jitshared/histogram.cpp Drops <cassert> so it no longer overwrites the JIT/interpreter assert macro.
src/coreclr/jitshared/compallocator.h Removes direct <assert.h> include that could overwrite the custom assert macro.
src/coreclr/jitshared/arenaallocator.h Removes direct <assert.h> include that could overwrite the custom assert macro.

Copy link
Member

@kg kg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jakobbotsch jakobbotsch merged commit 9515659 into main Mar 4, 2026
109 of 111 checks passed
@jakobbotsch jakobbotsch deleted the copilot/fix-jit-assert-issue branch March 4, 2026 10:33
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

6 participants