Skip to content

Operation with native integer constant that might overflow in unchecked context should be treated as not constant#45581

Merged
cston merged 5 commits intodotnet:masterfrom
cston:45525
Jul 3, 2020
Merged

Operation with native integer constant that might overflow in unchecked context should be treated as not constant#45581
cston merged 5 commits intodotnet:masterfrom
cston:45525

Conversation

@cston
Copy link
Contributor

@cston cston commented Jul 1, 2020

For conversions that depend on the platform, the conversion should be treated as not constant and computed at runtime rather than compile-time.

Fixes #42955
Fixes #45525
Fixes #45531

Test plan #38821

@cston cston force-pushed the 45525 branch 3 times, most recently from 8f81795 to a22dca6 Compare July 1, 2020 23:05
@cston cston marked this pull request as ready for review July 1, 2020 23:07
@cston cston requested a review from a team as a code owner July 1, 2020 23:07
<value>'{0}' cannot be sealed because containing 'record' is not sealed.</value>
</data>
<data name="WRN_ConstOutOfRangeChecked" xml:space="preserve">
<value>Constant value '{0}' may overflow '{1}' (use 'unchecked' syntax to override)</value>
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 2, 2020

Choose a reason for hiding this comment

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

may overflow [](start = 32, length = 12)

Do we want to add "at run-time"? #Closed

@cston cston requested a review from a team July 2, 2020 05:06
// Dev10 checks (minValue - 1) < value < (MaxValue + 1) + 1).
maySucceedAtRuntime = false;

// Dev10 checks (minValue - 1) < value < (maxValue + 1).
Copy link
Contributor

Choose a reason for hiding this comment

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

maxValue [](start = 54, length = 8)

Does this change accurately reflect what Dev10 does?

}

private ConstantValue FoldConstantNumericConversion(
private ConstantValue? FoldConstantNumericConversion(
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 2, 2020

Choose a reason for hiding this comment

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

FoldConstantNumericConversion [](start = 31, length = 29)

Are all existing consumers prepared able to deal with null as the result? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, although I've added a few more annotations and handled null in one case that is currently obscured by #45625.


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

Copy link
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 3)

@chsienki
Copy link
Member

chsienki commented Jul 3, 2020

Latest changes LGTM

@cston cston merged commit 29542b0 into dotnet:master Jul 3, 2020
@ghost ghost added this to the Next milestone Jul 3, 2020
@cston cston deleted the 45525 branch July 3, 2020 04:09
@JoeRobich JoeRobich modified the milestones: Next, 16.8.P1 Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

5 participants