Skip to content

[cppia] Generate real functions for abstract methods - #13106

Merged
Simn merged 1 commit into
developmentfrom
claude/cppia-abstract-methods
Nov 1, 2026
Merged

Simn merged 1 commit into
developmentfrom
claude/cppia-abstract-methods

Conversation

@Simn

@Simn Simn commented Oct 31, 2026

Copy link
Copy Markdown
Member

Fixes the intermittent mac-test (cpp, arm64) failures. In those runs, Host-debug bin/unit.cppia -jit crashed while loading the module with hxSehException at cpp/cppia/Host.hx line 45. That happened in about 1 in 3 jobs.

Cause

For an abstract method, CppCppia emitted a bare RETURN expression as the method body (the "dummy implementation that (should) not get called"), not a FUN. hxcpp's CppiaFunction::load casts every method body to ScriptCallable * without checking:

  • The interpreter only uses it through virtual methods, so it works by accident.
  • The JIT calls the non-virtual ScriptCallable::compile(). That reads compiled/body past the end of the 64-byte hx::RetVal: a heap over-read whose outcome depends on the heap layout.

The ASLR dependence explains the randomness. The crash never reproduced under lldb with ASLR disabled, and reproduced on every run with Guard Malloc. Debugging was done in #13105, where Guard Malloc pinpointed funExpr of unit.issues._Issue11666.Foo.foo being a hx::RetVal.

Fix

  • The C++ generator already builds a no-op tfunc for abstract methods, with the right arguments and @:value defaults. This moves it to a top-level CppRetyper.abstract_tfunc.
  • The cppia generator now uses it for methods without an expression in non-interface classes. hxcpp then gets a proper FUN, which it loads as a real ScriptCallable.

Testing

Issue11666 already covers this. In #13105, with this change on macOS arm64:

  • 3/3 cppia JIT runs under Guard Malloc passed. Without the change, the first run crashed.
  • 30/30 runs under lldb with ASLR, MallocScribble and MallocPreScribble passed.
  • The regular interp and JIT unit and sys runs passed.

A separate hardening change in hxcpp could make CppiaFunction::load reject non-ScriptCallable bodies, so a bad .cppia file fails cleanly instead of reading out of bounds.


Generated by Claude Code

The cppia generator emitted a bare RETURN expression as the body of an
abstract method. hxcpp reads every class method body as a ScriptCallable,
and when JIT compiling it calls the non-virtual ScriptCallable::compile on
it, which reads past the end of the much smaller RetVal object. Depending
on the heap layout, this crashed while loading the module, which caused
the intermittent hxSehException failures of the macOS arm64 cppia JIT
tests (triggered by Issue11666's abstract Foo.foo).

Reuse the no-op tfunc that the C++ generator already builds for abstract
methods, so cppia gets a proper FUN with the right arguments and defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Va4FXG8Zex7iQytzPnDKyg
@tobil4sk

Copy link
Copy Markdown
Member

The interpreter only uses it through virtual methods, so it works by accident.
The JIT calls the non-virtual ScriptCallable::compile(). That reads compiled/body past the end of the 64-byte hx::RetVal: a heap over-read whose outcome depends on the heap layout.

Maybe it would make more sense to handle this on the hxcpp side so that the cppia runtime is capable of handling abstract methods with no body to compile, rather than throwing a dummy function to it. I think @Aidan63 also worked on abstract functions in cppia (#10476), so maybe he has some comment about the approach.

@Simn

Simn commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

There's definitely something to fix in hxcpp anyway because it shouldn't crash like that. I'm happy to drop the dummy function once that's in place, but for now I really just want to get rid of this spurious failure, so I'll merge this.

@Simn
Simn merged commit e83bca2 into development Nov 1, 2026
118 of 119 checks passed
@Simn
Simn deleted the claude/cppia-abstract-methods branch November 1, 2026 06:44
Simn pushed a commit that referenced this pull request Nov 1, 2026
Write down what helped track down the macOS arm64 cppia JIT crash fixed
in #13106, so future investigations don't have to rediscover it. Kept
out of AGENTS.md since it is rarely needed; point an agent to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Va4FXG8Zex7iQytzPnDKyg
Simn added a commit that referenced this pull request Nov 1, 2026
* [docs] Add notes on debugging intermittent native crashes in CI

Write down what helped track down the macOS arm64 cppia JIT crash fixed
in #13106, so future investigations don't have to rediscover it. Kept
out of AGENTS.md since it is rarely needed; point an agent to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Va4FXG8Zex7iQytzPnDKyg

* [docs] Move the advice on large CI logs to AGENTS.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Va4FXG8Zex7iQytzPnDKyg

---------

Co-authored-by: Claude <noreply@anthropic.com>
fullofcaffeine pushed a commit to fullofcaffeine/haxe that referenced this pull request Nov 22, 2026
…13106)

The cppia generator emitted a bare RETURN expression as the body of an
abstract method. hxcpp reads every class method body as a ScriptCallable,
and when JIT compiling it calls the non-virtual ScriptCallable::compile on
it, which reads past the end of the much smaller RetVal object. Depending
on the heap layout, this crashed while loading the module, which caused
the intermittent hxSehException failures of the macOS arm64 cppia JIT
tests (triggered by Issue11666's abstract Foo.foo).

Reuse the no-op tfunc that the C++ generator already builds for abstract
methods, so cppia gets a proper FUN with the right arguments and defaults.

Claude-Session: https://claude.ai/code/session_01Va4FXG8Zex7iQytzPnDKyg

Co-authored-by: Claude <noreply@anthropic.com>
(cherry picked from commit e83bca2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants