Skip to content

Clear hx::Null's value when it holds null - #513

Open
Tutez64 wants to merge 1 commit into
openfl:mainfrom
Tutez64:bugfix/null-value-unset
Open

Tutez64 wants to merge 1 commit into
openfl:mainfrom
Tutez64:bugfix/null-value-unset

Conversation

@Tutez64

@Tutez64 Tutez64 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

A Bool argument with a default that a call leaves out comes as an hx::Null<bool> built from null,
whose constructor set isNull and left value unset. Default() only returns value when
isNull is false, but GCC at -O2 may compute isNull ? true : value without a branch, as
isNull | value: then the bytes the caller's frame held come into the result. In an OpenFL build,
new ZipEntry(name), whose constructor takes compress:Bool = true, stored 23, 25 or 103 in
compress, and compress ? 8 : 0, compiled as compress << 3, wrote 184 as the zip method:

ZipEntry_obj::__alloc:
    movzbl (%r12),%eax       ; isNull
    or     0x1(%r12),%al     ; | value, unset
    mov    %al,0x18(%rdx)    ; this->compress

Stock hxcpp 4.3.2 compiles the same code from the same generated source, so this is not new.

Null(), Null(null), and the constructors from a null Dynamic or cpp::Variant now value-
initialize value: 0, false, or an empty value for the class types Null is used with.

Built against this branch, the same generated source stores 1 each time, where main's runtime
stored 23, 25, 27, 43, 45, 61 over three rounds.

Test: test/regression/NullDefaultArgument builds each kind of Null over bytes that are not a
bool and checks the value is cleared; before the change, each one was left as 0xFE (254). The
regression tests on default arguments and boxed Bools still pass (DefaultFuncForeignThis,
CppiaDefaultArgFrames, CppiaBoolBoxing, CffiNekoNullBoolWithoutInit).

Null(), Null(null) and the constructors from a null Dynamic or Variant
left value unset. Default() reads it only when isNull is false, but GCC
at -O2 can compute `isNull ? true : value` as `isNull | value`: an
omitted Bool argument with a default of true then came out as the bytes
the caller's frame held (23, 25, 103), and `compress ? 8 : 0` gave 184.
Stock hxcpp 4.3.2 compiles the same code. value is now value-initialized.

Test: regression/NullDefaultArgument builds each kind of Null over bytes
that are not a bool and checks the value is cleared (each was 254).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tutez64 added a commit to Tutez64/Dungeon-Rampage-Haxe that referenced this pull request Dec 3, 2026
- air-compat 0.1.0, its first haxelib release: Digest, Encryption,
  ZipArchive and ZipEntry beside the WebSocket, which is unchanged.
- libhxcpp: upstream's main with the fix for a Bool argument with a
  default of true that, left out, could arrive as stack bytes
  (openfl/libhxcpp#513, open).

The game builds, connects over wss, the test mods give the same
last-run.json and the launcher's 24 mods load compiled.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant