Skip to content

Throw an f32 as a float; fix three casts to f32 - #350

Merged
ASDAlexander77 merged 2 commits into
mainfrom
fix-throw-f32
Sep 23, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
fix-throw-f32

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

  • Throw an f32 as a C++ float, not a double. A thrown f32 described itself as a double: on Windows it used the .N records with size 8, on Linux _ZTId. So catch (e: number) took it and read eight bytes of a four-byte value (1.5f came back as 0.125). A module that threw both an f32 and a double also kept whichever box thunk it built first. The f32 is now .M / _ZTIf. Typed and untyped catches read it, and a number catch takes it through a widening entry, the same way it takes an int:
    • Windows: a .N copy thunk.
    • Linux: an extra landing-pad clause, plus an fpext when binding.
  • Fixes the inverted NUMBER_F64 branch in LLVMRTTIHelperVCWin32::setType. It was harmless until f32 got names of its own.
  • Three casts to f32 were broken. Any <f32> of an any failed to compile, including <f32>e in an untyped catch, because ___unbox<f32> tries every boxed type:
    • boolean -> f32 had no lowering and became undef. It is now a uitofp.
    • index -> f32 went through index.casts, which only produce integers, and lowered to an invalid trunc. It now uses the sitofp that index -> number already used.
    • string -> f32 returned atof's double where a float belongs. ParseFloat now truncates to its result type.

Tests

  • New: 00throw_f32.ts, 00cast_to_f32.ts (compile, jit, and the rc/none corpus runs).
  • Windows Release: 2830/2830 passed.
  • Linux (WSL): 2824/2824 passed.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits September 23, 2026 15:03
A thrown f32 described itself as a double - the `.N` records with size 8 on
Windows, `_ZTId` on Linux - so `catch (e: number)` took it and read eight bytes
of a four-byte value (1.5f came back as 0.125), and a module throwing both kept
whichever box thunk it built first. It is now a C++ float (`.M` / `_ZTIf`):
typed and untyped catches read it, and a `number` catch takes it through a
widening entry, as it does an int (Windows: a `.N` copy thunk; Linux: an extra
clause plus fpext when binding).

Also fixes the inverted NUMBER_F64 branch in LLVMRTTIHelperVCWin32::setType,
harmless until f32 got names of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`<f32>e` in an untyped catch - and any `<f32>` of an `any` - failed to compile:
`___unbox<f32>` tries every boxed type, and three of its casts were bad.

- boolean -> f32 had no lowering (only boolean -> number did) and became undef
  with an "invalid cast" warning; it is now a uitofp.
- index -> f32 went through index.casts, which only make integers, and lowered
  to a trunc to f32 that the verifier rejects; a float now takes the sitofp
  that index -> number always used.
- string -> f32 returned atof's double as the float; ParseFloat now truncates
  to its result type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 47b64bc into main Sep 23, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-throw-f32 branch September 23, 2026 14:59
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