Skip to content

Commit 635d723

Browse files
authored
Fix15254 (#15257)
1 parent bacdc8a commit 635d723

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

src/FSharp.Core/prim-types.fs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ namespace Microsoft.FSharp.Core
15611561
// and devirtualizes calls to it based on "T".
15621562
let GenericEqualityERIntrinsic (x : 'T) (y : 'T) : bool =
15631563
GenericEqualityObj true fsEqualityComparerNoHashingER ((box x), (box y))
1564-
1564+
15651565
/// Implements generic equality between two values using "comp" for recursive calls.
15661566
//
15671567
// The compiler optimizer is aware of this function (see use of generic_equality_withc_inner_vref in opt.fs)
@@ -1621,13 +1621,14 @@ namespace Microsoft.FSharp.Core
16211621
when 'T : float = (# "ceq" x y : bool #)
16221622
when 'T : float32 = (# "ceq" x y : bool #)
16231623
when 'T : char = (# "ceq" x y : bool #)
1624+
when 'T : voidptr = (# "ceq" x y : bool #)
16241625
when 'T : nativeint = (# "ceq" x y : bool #)
16251626
when 'T : unativeint = (# "ceq" x y : bool #)
16261627
when 'T : string = System.String.Equals((# "" x : string #),(# "" y : string #))
16271628
when 'T : decimal = System.Decimal.op_Equality((# "" x:decimal #), (# "" y:decimal #))
16281629
when 'T : DateTime = DateTime.Equals((# "" x : DateTime #), (# "" y : DateTime #))
1629-
1630-
1630+
1631+
16311632
/// A compiler intrinsic generated during optimization of calls to GenericEqualityIntrinsic on tuple values.
16321633
//
16331634
// If no static optimization applies, this becomes GenericEqualityIntrinsic.
@@ -1646,9 +1647,10 @@ namespace Microsoft.FSharp.Core
16461647
when 'T : uint16 = (# "ceq" x y : bool #)
16471648
when 'T : uint32 = (# "ceq" x y : bool #)
16481649
when 'T : uint64 = (# "ceq" x y : bool #)
1649-
when 'T : float = (# "ceq" x y : bool #)
1650-
when 'T : float32 = (# "ceq" x y : bool #)
1650+
when 'T : float = (# "ceq" x y : bool #)
1651+
when 'T : float32 = (# "ceq" x y : bool #)
16511652
when 'T : char = (# "ceq" x y : bool #)
1653+
when 'T : voidptr = (# "ceq" x y : bool #)
16521654
when 'T : nativeint = (# "ceq" x y : bool #)
16531655
when 'T : unativeint = (# "ceq" x y : bool #)
16541656
when 'T : string = System.String.Equals((# "" x : string #),(# "" y : string #))

tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/GenericComparison.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,23 @@ module GenericComparison =
210210
let ``Equals09_fsx`` compilation =
211211
compilation
212212
|> verifyCompilation
213+
214+
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NativeIntComparison.fs"|])>]
215+
let ``NativeIntComparison_fs`` compilation =
216+
compilation
217+
|> asExe
218+
|> withOptimize
219+
|> withEmbeddedPdb
220+
|> withEmbedAllSource
221+
|> compileAndRun
222+
|> shouldSucceed
223+
224+
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"VoidPtrComparison.fs"|])>]
225+
let ``VoidPtrComparison_fs`` compilation =
226+
compilation
227+
|> asExe
228+
|> withOptimize
229+
|> withEmbeddedPdb
230+
|> withEmbedAllSource
231+
|> compileAndRun
232+
|> shouldSucceed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for https://github.com/dotnet/fsharp/issues/15254
2+
#nowarn "52"
3+
4+
open System
5+
6+
let default_nativeint = Unchecked.defaultof<nativeint>
7+
let intptr_nativeint = IntPtr.Zero
8+
let isSame = intptr_nativeint = default_nativeint
9+
10+
if not (isSame) then raise (new Exception "default_nativeint and intptr_nativeint compare is incorrect")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for https://github.com/dotnet/fsharp/issues/15254
2+
#nowarn "52"
3+
4+
open System
5+
6+
let default_voidptr = Unchecked.defaultof<voidptr>
7+
let intptr_voidptr = IntPtr.Zero.ToPointer()
8+
let isSame = intptr_voidptr = default_voidptr
9+
10+
if not (isSame) then raise (new Exception "default_voidptr and intptr_voidptr compare is incorrect")

0 commit comments

Comments
 (0)