Skip to content
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

Fix15254 #15257

Merged
merged 2 commits into from
May 24, 2023
Merged

Fix15254 #15257

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ namespace Microsoft.FSharp.Core
// and devirtualizes calls to it based on "T".
let GenericEqualityERIntrinsic (x : 'T) (y : 'T) : bool =
GenericEqualityObj true fsEqualityComparerNoHashingER ((box x), (box y))

/// Implements generic equality between two values using "comp" for recursive calls.
//
// The compiler optimizer is aware of this function (see use of generic_equality_withc_inner_vref in opt.fs)
Expand Down Expand Up @@ -1621,13 +1621,14 @@ namespace Microsoft.FSharp.Core
when 'T : float = (# "ceq" x y : bool #)
when 'T : float32 = (# "ceq" x y : bool #)
when 'T : char = (# "ceq" x y : bool #)
when 'T : voidptr = (# "ceq" x y : bool #)
when 'T : nativeint = (# "ceq" x y : bool #)
when 'T : unativeint = (# "ceq" x y : bool #)
when 'T : string = System.String.Equals((# "" x : string #),(# "" y : string #))
when 'T : decimal = System.Decimal.op_Equality((# "" x:decimal #), (# "" y:decimal #))
when 'T : DateTime = DateTime.Equals((# "" x : DateTime #), (# "" y : DateTime #))


/// A compiler intrinsic generated during optimization of calls to GenericEqualityIntrinsic on tuple values.
//
// If no static optimization applies, this becomes GenericEqualityIntrinsic.
Expand All @@ -1646,9 +1647,10 @@ namespace Microsoft.FSharp.Core
when 'T : uint16 = (# "ceq" x y : bool #)
when 'T : uint32 = (# "ceq" x y : bool #)
when 'T : uint64 = (# "ceq" x y : bool #)
when 'T : float = (# "ceq" x y : bool #)
when 'T : float32 = (# "ceq" x y : bool #)
when 'T : float = (# "ceq" x y : bool #)
when 'T : float32 = (# "ceq" x y : bool #)
when 'T : char = (# "ceq" x y : bool #)
when 'T : voidptr = (# "ceq" x y : bool #)
when 'T : nativeint = (# "ceq" x y : bool #)
when 'T : unativeint = (# "ceq" x y : bool #)
when 'T : string = System.String.Equals((# "" x : string #),(# "" y : string #))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,23 @@ module GenericComparison =
let ``Equals09_fsx`` compilation =
compilation
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NativeIntComparison.fs"|])>]
let ``NativeIntComparison_fs`` compilation =
compilation
|> asExe
|> withOptimize
|> withEmbeddedPdb
|> withEmbedAllSource
|> compileAndRun
|> shouldSucceed

[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"VoidPtrComparison.fs"|])>]
let ``VoidPtrComparison_fs`` compilation =
compilation
|> asExe
|> withOptimize
|> withEmbeddedPdb
|> withEmbedAllSource
|> compileAndRun
|> shouldSucceed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression test for https://github.com/dotnet/fsharp/issues/15254
#nowarn "52"

open System

let default_nativeint = Unchecked.defaultof<nativeint>
let intptr_nativeint = IntPtr.Zero
let isSame = intptr_nativeint = default_nativeint

if not (isSame) then raise (new Exception "default_nativeint and intptr_nativeint compare is incorrect")
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression test for https://github.com/dotnet/fsharp/issues/15254
#nowarn "52"

open System

let default_voidptr = Unchecked.defaultof<voidptr>
let intptr_voidptr = IntPtr.Zero.ToPointer()
let isSame = intptr_voidptr = default_voidptr

if not (isSame) then raise (new Exception "default_voidptr and intptr_voidptr compare is incorrect")