Skip to content

[StackIR] Emit unreachable for unwritable insts - #9283

Merged
tlively merged 4 commits into
mainfrom
stack-ir-unwritable-unreachable
Oct 21, 2026
Merged

tlively merged 4 commits into
mainfrom
stack-ir-unwritable-unreachable

Conversation

@tlively

@tlively tlively commented Oct 20, 2026

Copy link
Copy Markdown
Member

BinaryInstWriter emits an unreachable instruction when an expression has an unwritable heap type immediate or is a StringNew or StringEncode with a null-typed array operand, but StackIRGenerator::emit previously emitted a normal Basic StackInst for those expressions. Include StringNew and StringEncode with null-typed array operands in Properties::hasUnwritableTypeImmediate and emit unreachable in StackIRGenerator::emit when it returns true so StackIROptimizer and PrintStackIR see the unreachable instruction that will be written to the binary.

Also fix BinaryInstWriter::visitStringEncode to check whether curr->array (rather than curr->str) has a null type.

BinaryInstWriter emits an unreachable instruction when an expression has an unwritable heap type immediate or is a StringNew or StringEncode with a null-typed array operand, but StackIRGenerator::emit previously emitted a normal Basic StackInst for those expressions. Include StringNew and StringEncode with null-typed array operands in Properties::hasUnwritableTypeImmediate and emit unreachable in StackIRGenerator::emit when it returns true so StackIROptimizer and PrintStackIR see the unreachable instruction that will be written to the binary.

Also fix BinaryInstWriter::visitStringEncode to check whether curr->array (rather than curr->str) has a null type.
@tlively
tlively requested a review from a team as a code owner October 20, 2026 04:29
@tlively
tlively requested review from aheejin and removed request for a team October 20, 2026 04:29

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the handling of string array operations with null-typed array operands to ensure they are correctly identified as having unwritable type immediates. Specifically, it updates hasUnwritableTypeImmediate in src/ir/properties.h to check StringNew and StringEncode expressions, fixes a type check in BinaryInstWriter::visitStringEncode, and ensures StackIRGenerator::emit emits unreachable for these expressions. Test cases are also updated and added to verify the behavior. The review feedback suggests adding defensive null checks for sn->ref and se->array in hasUnwritableTypeImmediate to prevent potential null pointer dereferences.

Comment thread src/ir/properties.h
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@tlively
tlively enabled auto-merge (squash) October 21, 2026 00:23
@tlively
tlively merged commit 1c9c918 into main Oct 21, 2026
16 checks passed
@tlively
tlively deleted the stack-ir-unwritable-unreachable branch October 21, 2026 00:50
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