Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix SIGFPE caused by integer division overflow sinteger_t.min / (-1) in constant folding #6511

Merged
merged 3 commits into from
Feb 11, 2017

Conversation

MaskRay
Copy link
Contributor

@MaskRay MaskRay commented Feb 3, 2017

No description provided.

@WalterBright
Copy link
Member

I'm not sure how integer division produces a floating point exception?

In any case, this needs a test case.

@MaskRay MaskRay force-pushed the master branch 3 times, most recently from ee27bfe to db92c10 Compare February 3, 2017 08:50
@MaskRay
Copy link
Contributor Author

MaskRay commented Feb 3, 2017

The Mod function already checks for integer division overflow but the Div function didn't, I just copied the code. See http://stackoverflow.com/questions/17176221/is-int-min-1-defined-behavior-in-c for details.

        if (n2 == -1 && !type.isunsigned())
        {
            // Check for int.min % -1
            if (n1 == 0xFFFFFFFF80000000UL && type.toBasetype().ty != Tint64)
            {
                e2.error("integer overflow: int.min % -1");
                n2 = 1;
            }
            else if (n1 == 0x8000000000000000L) // long.min % -1
            {
                e2.error("integer overflow: long.min % -1");
                n2 = 1;
            }
        }

You will get a SIGFPE doing LONG_MIN / (-1) on Linux x86_64,

% /usr/bin/dmd /tmp/a.d
[1]    10707 floating point exception (core dumped)  /usr/bin/dmd /tmp/a.d

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
4682 [CTFE] Run-time Vs Compile-time of int.min % -1

@MartinNowak
Copy link
Member

SIGFPE is triggered on divide by zero as well and is used for any arithmetic errors.
The GNU C Library: Program Error Signals

@MartinNowak
Copy link
Member

Auto-merge toggled on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants