Skip to content

Check for right-hand operand of zero in lrem and irem - #6864

Merged
jdmpapin merged 1 commit into
eclipse-omr:masterfrom
hzongaro:vp-division-by-zero-in-lrem-irem
Jan 16, 2023
Merged

jdmpapin merged 1 commit into
eclipse-omr:masterfrom
hzongaro:vp-division-by-zero-in-lrem-irem

Conversation

@hzongaro

Copy link
Copy Markdown
Contributor

If the following program

public class Bug {
    public static final int sub(int i) {
        int[] arr = {1,2,3,4,5,6,7,8};
        long l = 0;
        return arr[-((int) (i % l))];
    }

    public static final void main(String[] args) {
        sub(1);
    }
}

is run with java -Xjit:count=0 Bug, the following assertion failure results:

Assertion failed at /root/hostdir/defects/issue15730/openj9-openjdk-jdk17/omr/compiler/optimizer/VPHandlers.cpp:8171: low <= high
VMState: 0x000514ff
        Node 0x7f87257752c0 [l2i]: reversed child constraint bounds

The problem is that the constrainIrem and constrainLrem Value Propagation handlers guard against a right-hand operand of zero if the left-hand operand is a constant, but not if the left-hand operand is a non-constant. In the latter case, a constraint in the range [1,-1] results. Notice that the upper bound of the range is less than the lower bound.

This change adds an additional check for a right-hand operand equal to zero if the left-hand operand is non-constant, avoiding creating an erroneous constraint for the result.

@hzongaro
hzongaro requested review from jdmpapin and removed request for vijaysun-omr January 13, 2023 02:21
@hzongaro

Copy link
Copy Markdown
Contributor Author

Devin @jdmpapin, may I ask you to review this fix?

@hzongaro
hzongaro requested a review from 0xdaryl January 13, 2023 17:16
@hzongaro

Copy link
Copy Markdown
Contributor Author

Daryl @0xdaryl, may I ask you to review as well?

@jdmpapin jdmpapin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actual fix looks reasonable

Comment thread compiler/optimizer/VPHandlers.cpp Resolved
The constrainIrem and constrainLrem methods guard against a right-hand
operand of zero if the left-hand operand is a constant, but not if the
left-hand operand is a non-constant.  In the latter case, a constraint
in the range [1,-1] results.

This change adds an additional check for a right-hand operand equal to
zero if the left-hand operand is non-constant, avoiding creating an
erroneous constraint for the result.

Signed-off-by:  Henry Zongaro <zongaro@ca.ibm.com>
@hzongaro
hzongaro force-pushed the vp-division-by-zero-in-lrem-irem branch from 513f3f2 to 43ba527 Compare January 13, 2023 18:03
@hzongaro

Copy link
Copy Markdown
Contributor Author

Devin @jdmpapin, thanks for the review. I've removed the debugging trace messages that I had inadvertently left behind. It's ready for another review.

@jdmpapin

Copy link
Copy Markdown
Contributor

Jenkins build all

@hzongaro
hzongaro removed the request for review from 0xdaryl January 16, 2023 13:22
@hzongaro

Copy link
Copy Markdown
Contributor Author

@jdmpapin Devin, FYI - I removed @0xdaryl as a reviewer for this simple fix. I had forgotten that you are a committer for OMR.

@jdmpapin jdmpapin self-assigned this Jan 16, 2023
@jdmpapin
jdmpapin merged commit 333650d into eclipse-omr:master Jan 16, 2023
@hzongaro
hzongaro deleted the vp-division-by-zero-in-lrem-irem branch January 16, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants