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 issue 19497 - the program crash using dmd with -O, it works fine … #9113

Merged
merged 2 commits into from Dec 29, 2018

Conversation

aG0aep6G
Copy link
Contributor

…without optimizations.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @aG0aep6G! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
19497 critical the program crash using dmd with -O, it works fine without optimizations.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "stable + dmd#9113"

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

Looks fine to me, but I'll wait for someone who understands what that code is actually doing. cc @WalterBright

@@ -443,7 +443,7 @@ void cdeq(ref CodeBuilder cdb,elem *e,regm_t *pretregs)
postinc = e11.EV.E2.EV.Vint;
if (e11.Eoper == OPpostdec)
postinc = -postinc;
getlvalue(cdb,&cs,e11,RMstore);
getlvalue(cdb,&cs,e1,RMstore);
Copy link
Member

Choose a reason for hiding this comment

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

getlvalue(cdb,&cs,e11,RMstore | retregs);
and
https://github.com/dlang/dmd/blob/master/src/dmd/backend/cgxmm.d#L257
have more or less the same code, should they be changed, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first one seems to have a workaround following it:

dmd/src/dmd/backend/cod4.d

Lines 715 to 716 in 5cb179f

if (I64 && sz < 8)
cs.Irex &= ~REX_W; // incorrectly set by getlvalue()

Blame leads to this commit: 521e68c. Unfortunately, there's hardly a hint as to what issue was fixed there. It looks like removing the workaround, and fixing the getlvalue call instead, could work. But maybe we should first find/add a test that breaks without the workaround.

Regarding the one in cgxmm.d, I got nothing.

Copy link
Member

Choose a reason for hiding this comment

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

The first one seems to have a workaround following it:

This code triggers the workaround (Win64):

// REQUIRES: -O

int toStringz(string s) { return s.length > 0 ? s[0] : 0; }

private void toAStringz(in string[] a, int*az)
{
    foreach (string s; a)
    {
        *az++ = toStringz(s);
    }
}

void main()
{
    string[1] sa = [ "abc" ];
    int[2] tgt = 0x2a;
    toAStringz(sa[], tgt.ptr);
    assert(tgt[0] == 'a');
    assert(tgt[1] == 0x2a);
}

It also passes if e11 is replaced by e1 instead of the workaround.

Copy link
Member

Choose a reason for hiding this comment

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

Regarding the one in cgxmm.d, I got nothing.

It is hit by the same code when using float, double or __vector(T) instead of int, but doesn't seem to be affected by the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a commit that removes the workaround and adds your test.

@gtoutoungis
Copy link

Hi, I am George who submitted this bug.
Thanks for the fix, waiting for the new version of dmd :)
And Thanks to maintain and improve such a wonderful programming language.

looking at the test case, just I wonder how it works. maybe I miss something!!

void test19497() // https://issues.dlang.org/show_bug.cgi?id=19497
{
    alias Seq(stuff ...) = stuff;
    static foreach (T; Seq!(ubyte, ushort, uint, ulong, byte, short, int, long))
    {{
        T[2] data = 0x2A;
        T* q = &data[0];
        *q++ = cast(T) 0x1122334455667788;
        if (*q != 0x2A) assert(false);
    }}
}

as q is a pointer to data[0], and we initialize the data[2] with 0x2A.
we put a value in data[0] using the pointer q, and incrementing q using q++.
then q should point to data[1] and not data[2].
so how we test *q to content of data[2] which is 0x2A !!

Best Regards,
Georges Toutoungis

@aG0aep6G
Copy link
Contributor Author

as q is a pointer to data[0], and we initialize the data[2] with 0x2A.

We initialize both data[0] and data[1] to 0x2A. There is no data[2].

we put a value in data[0] using the pointer q, and incrementing q using q++.
then q should point to data[1] and not data[2].

That's right. After the increment, q points to data[1].

so how we test *q to content of data[2] which is 0x2A !!

There is no data[2]. I'm asserting that data[1] still contains 0x2A. With the bug, the assignment to data[0]also wrote over data[1] when T = int.

@gtoutoungis
Copy link

gtoutoungis commented Dec 26, 2018 via email

@thewilsonator
Copy link
Contributor

Is this good to go now?

@WalterBright
Copy link
Member

The test suite for DMC++ has much more extensive code generator tests. Let me run that first.

Also, now that the backend is in D, why aren't we getting the test coverage information for the back end?

@WalterBright
Copy link
Member

This change is crashing DMC++ when running its test suite.

@rainers
Copy link
Member

rainers commented Dec 27, 2018

This change is crashing DMC++ when running its test suite.

Too bad. Maybe the workaround from line 714 should be copied to the original location at line 446.

@WalterBright
Copy link
Member

Here's the test case that fails when this PR is added:
#9146

@rainers
Copy link
Member

rainers commented Dec 27, 2018

Maybe the workaround from line 714 should be copied to the original location at line 446.

That seems to work, too. But let's see #9146 fail the testers with the current version...

@rainers
Copy link
Member

rainers commented Dec 27, 2018

But let's see #9146 fail the testers with the current version...

ccompile.d doesn't fail on the auto-tester. @WalterBright Did it do that for you with the translated version or only for the C version?

@WalterBright
Copy link
Member

It did it for the translated version. At the moment, I cannot explain why it is failing on my system and not the autotester.

@WalterBright
Copy link
Member

The problems I was seeing with this were my own construction.

@WalterBright WalterBright merged commit 973c000 into dlang:stable Dec 29, 2018
@aG0aep6G aG0aep6G deleted the 19497 branch December 31, 2018 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants