Repository navigation
[cppia] Generate real functions for abstract methods - #13106
Conversation
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
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. |
|
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. |
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] 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>
…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)
Fixes the intermittent
mac-test (cpp, arm64)failures. In those runs,Host-debug bin/unit.cppia -jitcrashed while loading the module withhxSehExceptionatcpp/cppia/Host.hx line 45. That happened in about 1 in 3 jobs.Cause
For an abstract method,
CppCppiaemitted a bareRETURNexpression as the method body (the "dummy implementation that (should) not get called"), not aFUN. hxcpp'sCppiaFunction::loadcasts every method body toScriptCallable *without checking:ScriptCallable::compile(). That readscompiled/bodypast the end of the 64-bytehx::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
funExprofunit.issues._Issue11666.Foo.foobeing ahx::RetVal.Fix
tfuncfor abstract methods, with the right arguments and@:valuedefaults. This moves it to a top-levelCppRetyper.abstract_tfunc.FUN, which it loads as a realScriptCallable.Testing
Issue11666already covers this. In #13105, with this change on macOS arm64:MallocScribbleandMallocPreScribblepassed.A separate hardening change in hxcpp could make
CppiaFunction::loadreject non-ScriptCallablebodies, so a bad.cppiafile fails cleanly instead of reading out of bounds.Generated by Claude Code