L1A/L1B PASS; L2 FAIL: FloatConstant bug in VarReturnQuad#554
Open
opencode-agent[bot] wants to merge 1 commit into
Open
L1A/L1B PASS; L2 FAIL: FloatConstant bug in VarReturnQuad#554opencode-agent[bot] wants to merge 1 commit into
opencode-agent[bot] wants to merge 1 commit into
Conversation
Co-authored-by: LSantha <LSantha@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spec compliance report
Details
l1a Implementation
core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:1842,core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:4241(wreturn helper)The L1A implementation correctly handles
freturn:visit_freturn()at line 1842 callswreturn(JvmType.FLOAT, true)wreturn()at line 4241 pops aWordItem(32-bit) from the virtual stack forJvmType.FLOATEAX(32-bit) orRAX(64-bit non-reference) registervisit_return()which cleans the virtual stack and emits a jump to the method footerl1b Implementation
core/src/core/org/jnode/vm/x86/compiler/l1b/X86BytecodeVisitor.java:2224,core/src/core/org/jnode/vm/x86/compiler/l1b/X86BytecodeVisitor.java:5225(wreturn helper)The L1B implementation is functionally identical to L1A with added bytecode counting. Same correct behavior:
visit_freturn()at line 2224 callswreturn(JvmType.FLOAT, true)wreturn()at line 5225 handles float return value identically to L1Avisit_return()and stack frame footerl2 Implementation
core/src/core/org/jnode/vm/compiler/ir/IRGenerator.java:967(IR generation)core/src/core/org/jnode/vm/x86/compiler/l2/GenericX86CodeGenerator.java:347(code generation)core/src/core/org/jnode/vm/x86/compiler/l2/L2ByteCodeSupportChecker.java(support check - freturn not listed as unsupported)generateCodeFor(VarReturnQuad)The L2 implementation has a critical bug in
GenericX86CodeGenerator.generateCodeFor(VarReturnQuad):IR Generation (correct):
IRGenerator.visit_freturn()at line 967 correctly creates aVarReturnQuadwithOperand.FLOATtypeSupport Check (correct):
L2ByteCodeSupportCheckerdoes NOT overridevisit_freturn(), so it inherits the empty implementation fromBytecodeVisitorSupport(line 440), meaning freturn is considered supportedCode Generation (BUG at line 347-392):
The
generateCodeFor(VarReturnQuad)method handles CONSTANT addressing mode but only checks forIntConstantandLongConstant:When a method returns a constant float (e.g.,
return 1.0f;), the IR will have aFloatConstantoperand, causingIllegalArgumentExceptionat runtime.Stack mode handling (works by accident):
For non-constant float returns (stack/register mode), the code at line 376 checks:
Since
Operand.FLOATis notLONGorDOUBLE, it falls through to the 32-bit move to EAX, which happens to work for float values (IEEE 754 bit pattern preserved).JVM Spec References
..., value → [empty](consumes one float, stack empty after)Summary
FloatConstanthandling inVarReturnQuadcode generationCloses #280
opencode session | github run