-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 Double-to-Long overflow check #73016
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -605,7 +605,8 @@ End Class | |
New TypeAndValue(uint64Type, CULng(18)), | ||
New TypeAndValue(decimalType, CDec(-11.3)), | ||
New TypeAndValue(doubleType, CDbl(&HF000000000000000UL)), | ||
New TypeAndValue(doubleType, CDbl(&H70000000000000F0L)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. Sounds reasonable. |
||
New TypeAndValue(doubleType, CDbl(&H8000000000000000L)), | ||
New TypeAndValue(doubleType, CDbl(&H7FFFFFFFFFFFFC00L)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these cases be added to |
||
New TypeAndValue(typeCodeType, Int32.MinValue), | ||
New TypeAndValue(typeCodeType, Int32.MaxValue), | ||
New TypeAndValue(typeCodeType, CInt(-3)), | ||
|
@@ -1165,7 +1166,8 @@ End Class | |
New TypeAndValue(uint64Type, CULng(18)), | ||
New TypeAndValue(decimalType, CDec(-11.3)), | ||
New TypeAndValue(doubleType, CDbl(&HF000000000000000UL)), | ||
New TypeAndValue(doubleType, CDbl(&H70000000000000F0L)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
New TypeAndValue(doubleType, CDbl(&H8000000000000000L)), | ||
New TypeAndValue(doubleType, CDbl(&H7FFFFFFFFFFFFC00L)), | ||
New TypeAndValue(typeCodeType, Int32.MinValue), | ||
New TypeAndValue(typeCodeType, Int32.MaxValue), | ||
New TypeAndValue(typeCodeType, CInt(-3)), | ||
|
@@ -5095,5 +5097,42 @@ End Module | |
]]>) | ||
End Sub | ||
|
||
<WorkItem(73032, "https://github.com/dotnet/roslyn/issues/73032")> | ||
<Fact()> | ||
Public Sub ConvertLargeDoubleConstantsAndLiteralsToLong() | ||
Dim compilation = CreateCompilationWithMscorlib40AndVBRuntime( | ||
<compilation> | ||
<file name="a.vb"><![CDATA[ | ||
Module Program | ||
Sub Main() | ||
System.Console.WriteLine(CType(CDbl(&H8000000000000000L), Long)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Instead of outputting the values, I think we should compare them with result of conversions performed at runtime. For example it is not obvious to me that the values in the output are correct. I think the overflow check for VB is set to true by default, but it would be good to set this option explicitly ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In each case, the Long argument to CDbl is the expected result of calling CType. So I could write
and verify that the output is True. Is that acceptable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to rely on compile time constant folding for equality, which would be desirable to avoid. The goal is to compare result of compile time constant folding with result that doesn't rely on constant folding. I have something like the following in mind:
|
||
System.Console.WriteLine(CType(CDbl(&H8000000000000400L), Long)) | ||
System.Console.WriteLine(CType(-9.0E+18, Long)) | ||
System.Console.WriteLine(CType(CDbl(&H8FFFFFFFFFFFFC00L), Long)) | ||
System.Console.WriteLine(CType(CDbl(&H9000000000000000L), Long)) | ||
System.Console.WriteLine(CType(CDbl(&H7000000000000000L), Long)) | ||
System.Console.WriteLine(CType(CDbl(&H7000000000000400L), Long)) | ||
System.Console.WriteLine(CType(9.0E+18, Long)) | ||
System.Console.WriteLine(CType(CDbl(&H7FFFFFFFFFFFFC00L), Long)) | ||
End Sub | ||
End Module | ||
]]></file> | ||
</compilation>, options:=TestOptions.ReleaseExe) | ||
|
||
Dim expectedOutput = <![CDATA[ | ||
-9223372036854775808 | ||
-9223372036854774784 | ||
-9000000000000000000 | ||
-8070450532247929856 | ||
-8070450532247928832 | ||
8070450532247928832 | ||
8070450532247929856 | ||
9000000000000000000 | ||
9223372036854774784 | ||
]]> | ||
|
||
CompileAndVerify(compilation, expectedOutput:=expectedOutput).VerifyDiagnostics() | ||
End Sub | ||
|
||
End Class | ||
End Namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use the other value from the description,
&H7000000000000400L
, instead of this case?