Skip to content

Fix in optimizer to always respect refkind of vararg arguments#26123

Merged
VSadov merged 5 commits intodotnet:masterfrom
VSadov:Fix26113
Apr 14, 2018
Merged

Fix in optimizer to always respect refkind of vararg arguments#26123
VSadov merged 5 commits intodotnet:masterfrom
VSadov:Fix26113

Conversation

@VSadov
Copy link
Copy Markdown
Member

@VSadov VSadov commented Apr 12, 2018

Optimizer has all the information about refkinds, but chooses not to use it for __arglist . As a result vararg arguments are treated as always byval, which may allow optimizing them to stack values. That, in turns, result in byref arguments being effectively passed by value (and triggering an assert in codegen).

This change makes optimizer use the refkinds of vararg arguments.

The bug is not recent, and the feature is not extremely popular, so fixing in v.Next / master seems appropriate.

Fixes:#26113

@VSadov VSadov requested a review from a team as a code owner April 12, 2018 21:29
if (i < parameters.Length)
/// <summary>
/// Computes the desired refkind of the argument.
/// Consiuders all the cases where ref kinds are explicit, omitted, vararg cases.
Copy link
Copy Markdown
Contributor

@cston cston Apr 12, 2018

Choose a reason for hiding this comment

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

Typo: Considers #Resolved


for (int i = 0; i < arguments.Length; i++)
{
RefKind refKind = argRefKindsOpt.IsDefaultOrEmpty ? RefKind.None : node.ArgumentRefKindsOpt[i];
Copy link
Copy Markdown
Contributor

@cston cston Apr 12, 2018

Choose a reason for hiding this comment

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

node.ArgumentRefKindsOpt [](start = 83, length = 24)

argRefKindsOpt #Resolved

@VSadov VSadov changed the title Fixes:#26113 Fix in optimizer to always respect refkind of vararg arguments Apr 12, 2018
@VSadov
Copy link
Copy Markdown
Member Author

VSadov commented Apr 12, 2018

@dotnet/roslyn-compiler - please review

@VSadov
Copy link
Copy Markdown
Member Author

VSadov commented Apr 12, 2018

Tests seems to pass locally. Perhaps some issues with CI (the errors do not make a lot of sense).
Will rerun later.

@VSadov
Copy link
Copy Markdown
Member Author

VSadov commented Apr 12, 2018

Actually it looks like coreclr does not support varargs.
(possibly problems with references, but TypedReference is reported missing.)

public void VarargByRef()
{

var code = @"
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.

nit: empty line

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.

Other places as well.


In reply to: 181471418 [](ancestors = 181471418)

Copy link
Copy Markdown
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 5)

@VSadov VSadov merged commit 5e1c334 into dotnet:master Apr 14, 2018
@VSadov VSadov deleted the Fix26113 branch April 14, 2018 17:36
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.

Optimizer creates copies of a local when passed by ref

4 participants