Skip to content

fix(mlir): null-init ptr statics + short-circuit and/or (#230) - #249

Merged
cursor[bot] merged 2 commits into
mainfrom
cursor/mlir-null-statics-b994
Aug 9, 2026
Merged

cursor[bot] merged 2 commits into
mainfrom
cursor/mlir-null-statics-b994

Conversation

@godofecht

@godofecht godofecht commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Toward #230 (doom-flow on MLIR).

Triage / merge order: independent of #248 (no overlapping files). Prefer merging this first — it unblocks further #230 WAD/I/O work. #248 is gallery/pthreads and can land anytime.

Browser testing showed MLIR doom either crashing or booting to a black canvas with W_ReadLump: incomplete read. Two generator bugs contributed to the crash/UB path:

Fixes

  1. Null-init pointer module statics — bare llvm.mlir.global … : !llvm.ptr lowered to LLVM ptr undef, so null checks failed. Emit an init region with llvm.mlir.zero.
  2. Short-circuit and/or — eager arith.andi/ori evaluated getenv(...) == null or p[0] == 0 and dereferenced null. Lower with scf.if so the RHS is skipped when the LHS decides.

Still open for #230

Even with these fixes + #247 --wasm32, MLIR doom reaches “running 640×400” but does not render; page log shows incomplete WAD reads. C→emcc still plays. Next likely: remaining LP64-vs-ILP32 handle/layout mismatches in wad I/O beyond the libc remap.

doom-flow Pages

Cannot push to godofecht/doom-flow (403). Local patch keeps Pages on the working C bundle until MLIR renders.

Test plan

  • pytest tests/unit/test_mlir_null_ptr_statics.py
  • pytest tests/unit/test_mlir_generator.py::TestMLIRNullPointerLiterals (updated for null-init globals)
  • pytest tests/unit/test_mlir_chained_ast.py
  • CI green
  • Manual: MLIR doom still incomplete-reads IWAD (known)
Open in Web Open in Cursor 

Bare `llvm.mlir.global … : !llvm.ptr` lowered to `ptr undef`, so doom-flow
null checks failed. Emit `llvm.mlir.zero` init bodies instead.

Boolean `and`/`or` used eager `arith.andi`/`ori`, so
`getenv(...) == null or p[0] == 0` dereferenced null. Lower with `scf.if`
so the RHS is skipped when the LHS decides (needed for #230).

Co-authored-by: Abhishek Shivakumar <[email protected]>
@cursor

cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

The generator now emits llvm.mlir.zero bodies for module-scope
pointer globals; update the stale bare-global assertion so CI passes.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@cursor
cursor Bot merged commit 5fcfecf into main Aug 9, 2026
14 checks passed
@cursor
cursor Bot deleted the cursor/mlir-null-statics-b994 branch August 9, 2026 16:22
cursor Bot pushed a commit that referenced this pull request Aug 9, 2026
godofecht pushed a commit that referenced this pull request Aug 9, 2026
…b994

fix(mlir): null-init ptr statics + short-circuit and/or (#230)
godofecht added a commit that referenced this pull request Aug 9, 2026
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.

2 participants