Skip to content

Fix inline local declaration codegen#211

Open
gshaowei6 wants to merge 2 commits into
Syncleus:masterfrom
gshaowei6:fix-inline-assignment-chain-99
Open

Fix inline local declaration codegen#211
gshaowei6 wants to merge 2 commits into
Syncleus:masterfrom
gshaowei6:fix-inline-assignment-chain-99

Conversation

@gshaowei6
Copy link
Copy Markdown

@gshaowei6 gshaowei6 commented May 16, 2026

Fixes #99.
Also fixes #97.

This updates BlockWriter to hoist primitive local declarations that javac exposes as first-write declarations inside inline assignment expressions.

Two paths are covered:

  • if/else branches that declare the same source local now emit one outer declaration and suppress branch-local type prefixes, so chained assignments generate result = assignMe = value; instead of result = int assignMe = value;.
  • inline assignments nested inside expression statements, such as method arguments, now emit the local declaration before the expression and then write the inline assignment as z=1, avoiding CodeGenException: we can't declare this int here.

Tests:

  • RED check for [Bounty $20] Inline declarations throw exception. #97: after changing AssignAndPassAsParameterSimpleTest to expect successful OpenCL generation, it failed with CodeGenException: /* we can't declare this int here */ before the expression-level hoist.
  • mvn "-Dtest=com.aparapi.codegen.test.AssignAndPassAsParameterSimpleTest" test (2 tests, 0 failures)
  • mvn "-Dtest=com.aparapi.codegen.test.AssignAndPassAsParameterSimpleTest,com.aparapi.codegen.test.AssignAndPassAsParameterTest,com.aparapi.codegen.test.FirstAssignInExpressionTest,com.aparapi.codegen.test.FirstAssignInExpression2Test,com.aparapi.codegen.test.ConstantAssignInExpressionTest,com.aparapi.codegen.test.MultipleAssignExprTest,com.aparapi.codegen.test.MultipleAssignTest" test (14 tests, 0 failures)
  • mvn "-Dtest=com.aparapi.codegen.test.*Test" test; the Docker run exited 0 and target/surefire-reports contains 434 tests, 0 failures, 0 errors, 2 skipped
  • git diff --check

@gshaowei6 gshaowei6 changed the title Fix local declaration hoisting in inline assignments Fix inline local declaration codegen May 16, 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.

[Bounty $20] Two inline assignments in the same statement produce incorrect opencl code. [Bounty $20] Inline declarations throw exception.

1 participant