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 9356 - -inline with inout and append generates wrong code #2269

Merged
merged 3 commits into from
Nov 9, 2013

Conversation

yebblies
Copy link
Member

Force the result expression from inlining a function to match the type of the call expression.

eg the inlined expression from
inout(char)[] bar (inout(char)[] a) { return a; }
called with:
bar("abc")
should be
immutable(char)[]
but the type of the actual return expression is
inout(char)[].

Coupled with an optimistic if/else in e2ir, this generates wrong code.

http://d.puremagic.com/issues/show_bug.cgi?id=9356

@@ -1332,6 +1332,8 @@ Expression *CallExp::inlineScan(InlineScanState *iss)
}
}

if (e && type->ty != Tvoid)
e->type = type;
Copy link
Member

Choose a reason for hiding this comment

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

Just poking in the dark, but wouldn't this need some CastExp in case there is actually some conversion to do, like int -> long.

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK those are all added during semantic on the return statement. This problem only occurs for conversions that do not require a cast on the return statement, such as inout -> whatever, which must happen on the caller side.

Copy link
Member Author

Choose a reason for hiding this comment

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

Although with that segfault, who knows.

@yebblies
Copy link
Member Author

yebblies commented Jul 3, 2013

Gah, sometimes the CallExp doesn't have a type somehow.

@9rnsr
Copy link
Contributor

9rnsr commented Sep 30, 2013

Please rebase.

Force the result expression from inlining a function to match the type of the call expression
@yebblies
Copy link
Member Author

yebblies commented Nov 7, 2013

Turns out inlineScan was still being run on unittest bodies when they were disabled, and hadn't had semantic run. Hence no type and the crash. Hopefully works now.

@yebblies
Copy link
Member Author

yebblies commented Nov 8, 2013

Updated to remove copy-paste mistake from yebblies@3f9e446#commitcomment-4543998

MartinNowak added a commit that referenced this pull request Nov 9, 2013
Fix Issue 9356 - -inline with inout and append generates wrong code
@MartinNowak MartinNowak merged commit 5660520 into dlang:master Nov 9, 2013
@yebblies yebblies deleted the issue9356 branch November 10, 2013 03:05
@yebblies
Copy link
Member Author

Thanks.

@9rnsr
Copy link
Contributor

9rnsr commented Feb 6, 2014

This change has caused ICE regression 12079.

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

Successfully merging this pull request may close these issues.

4 participants