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

Issue 12500 - ICE in codegen when multiplying an incremented size_t by a double #4415

Merged
merged 3 commits into from Feb 18, 2015

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Feb 16, 2015

https://issues.dlang.org/show_bug.cgi?id=12500

AST simplification will fix backend ICE, and additionally improve error diagnostic in issue 14102.

For the collection of test cases for assgnment-related issues.
…_t by a double

Move lvalue-ness handling of BinAssignExp into glue layer.

elem *el;
elem *ev;
if (be->e1->op == TOKcast)
Copy link
Member

Choose a reason for hiding this comment

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

Why is it valid for the lhs to be a CastExp? I didn't think this was a valid ast... Which expressions produce this, and is it a frontend bug that they get this far?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's intended front-end result. Although it looks problematic as AST structure, but is necessary for the dmd backend codegen.
If the assigned lhs type is narrower than rhs, CastExp will be added. For example:

short a; int b;
a += b;  // Rewritten to: cast(int)a += b;
         // and it's equivalent with b = cast(short)(cast(int)a + b);

If we just remove the cast, backend ICE will happen, because a backend operand OPaddass cannot have short sized expression in its lhs.

I've tried to remove the lhs cast, but I couldn't do it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see why it's necessary, the dmd backend limitation could (should) be worked around in the glue layer so other backends aren't burdened with supporting the invalid ast construct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the workaround code for the dmd backend. ldc and gdc already have similar code.

https://github.com/D-Programming-GDC/GDC/blob/master/gcc/d/d-codegen.cc#L1738
https://github.com/ldc-developers/ldc/blob/master/gen/toir.cpp#L533

So, there is no need to fix it in a hurry.

@WalterBright
Copy link
Member

Auto-merge toggled on

braddr added a commit that referenced this pull request Feb 18, 2015
Issue 12500 - ICE in codegen when multiplying an incremented size_t by a double
@braddr braddr merged commit b185941 into dlang:master Feb 18, 2015
@9rnsr 9rnsr deleted the fix12500 branch February 18, 2015 10:00
@9rnsr
Copy link
Contributor Author

9rnsr commented Feb 27, 2015

This PR introduced a regression: https://issues.dlang.org/show_bug.cgi?id=14220

However, I think it's caused by a hidden backend optimizer bug, and just unfortunately surfaced by this PR.

@WalterBright @yebblies I posted a reduced test case for 14220 in bugzilla. Can you see the backend issue?

@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=14341

Expression *e1 = e->e1;
while (e->e1->op == TOKcast)
e1 = ((CastExp *)e1)->e1;
result = interpret(e1, istate, goal);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is right, it will not evaluate the RHS at all.
eg

int ctfetest()
{
    int x;
    ++(x += 1);
    return x == 2;
}

void main()
{
    enum v = ctfetest();
    assert(v == ctfetest());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I filed the new CTFE issue: https://issues.dlang.org/show_bug.cgi?id=14371

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