-
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 all commits
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,46 @@ 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) = ConvertToLong(CDbl(&H8000000000000000L))) | ||
System.Console.WriteLine(CType(CDbl(&H8000000000000400L), Long) = ConvertToLong(CDbl(&H8000000000000400L))) | ||
System.Console.WriteLine(CType(-9.0E+18, Long) = ConvertToLong(-9.0E+18)) | ||
System.Console.WriteLine(CType(CDbl(&H8FFFFFFFFFFFFC00L), Long) = ConvertToLong(CDbl(&H8FFFFFFFFFFFFC00L))) | ||
System.Console.WriteLine(CType(CDbl(&H9000000000000000L), Long) = ConvertToLong(CDbl(&H9000000000000000L))) | ||
System.Console.WriteLine(CType(CDbl(&H7000000000000000L), Long) = ConvertToLong(CDbl(&H7000000000000000L))) | ||
System.Console.WriteLine(CType(CDbl(&H7000000000000400L), Long) = ConvertToLong(CDbl(&H7000000000000400L))) | ||
System.Console.WriteLine(CType(9.0E+18, Long) = ConvertToLong(9.0E+18)) | ||
System.Console.WriteLine(CType(CDbl(&H7FFFFFFFFFFFFC00L), Long) = ConvertToLong(CDbl(&H7FFFFFFFFFFFFC00L))) | ||
End Sub | ||
|
||
Function ConvertToLong(x as Double) As Long | ||
Return CType(x, Long) | ||
End Function | ||
End Module | ||
]]></file> | ||
</compilation>, options:=TestOptions.ReleaseExe.WithOverflowChecks(True)) | ||
|
||
Dim expectedOutput = <![CDATA[ | ||
True | ||
True | ||
True | ||
True | ||
True | ||
True | ||
True | ||
True | ||
True | ||
]]> | ||
|
||
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?