From e312bfc0a9451af810c28fd1fa8bebee24ffa472 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 8 Sep 2023 01:02:32 +0200 Subject: [PATCH 1/4] Fix fgDebugCheckFlags checks for FTN_ADDR --- src/coreclr/jit/fgdiagnostic.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/jit/fgdiagnostic.cpp b/src/coreclr/jit/fgdiagnostic.cpp index e79bdb0e46368a..b51bfc6c38d637 100644 --- a/src/coreclr/jit/fgdiagnostic.cpp +++ b/src/coreclr/jit/fgdiagnostic.cpp @@ -3152,6 +3152,7 @@ void Compiler::fgDebugCheckFlags(GenTree* tree) // Some of these aren't handles to invariant data... if ((handleKind == GTF_ICON_STATIC_HDL) || // Pointer to a mutable class Static variable (handleKind == GTF_ICON_BBC_PTR) || // Pointer to a mutable basic block count value + (handleKind == GTF_ICON_FTN_ADDR) || // Pointer to a potentially mutable VM slot (handleKind == GTF_ICON_GLOBAL_PTR)) // Pointer to mutable data from the VM state { // For statics, we expect the GTF_GLOB_REF to be set. However, we currently From 1b612201306dd4a5b77e8cdd15ee1ae0304c0241 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 8 Sep 2023 01:07:11 +0200 Subject: [PATCH 2/4] Add test --- .../JitBlue/Runtime_91505/Runtime_91505.cs | 24 +++++++++++++++++++ .../Runtime_91505/Runtime_91505.csproj | 9 +++++++ 2 files changed, 33 insertions(+) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.cs new file mode 100644 index 00000000000000..94a0fd8a6f76fb --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; +using Xunit; + +public class Runtime_91505 +{ + [Fact] + public static void TestEntryPoint() + { + Test(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static unsafe long Test() + { + delegate* ptr = &Foo; + return *(long*)ptr; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Foo() {} +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj new file mode 100644 index 00000000000000..e58e7a9e72c63e --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj @@ -0,0 +1,9 @@ + + + True + true + + + + + From 8f7cdd2341286f3a12b998c4d0c40c03b8edcd97 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 8 Sep 2023 01:12:05 +0200 Subject: [PATCH 3/4] Update Runtime_91505.csproj --- .../JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj index e58e7a9e72c63e..1981001110bbe0 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91505/Runtime_91505.csproj @@ -1,7 +1,7 @@ True - true + true From 376a4ab89baa99280a2e5f22b6fb67fab3df193f Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 9 Sep 2023 23:55:38 +0200 Subject: [PATCH 4/4] Fix build --- src/coreclr/jit/fgdiagnostic.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/jit/fgdiagnostic.cpp b/src/coreclr/jit/fgdiagnostic.cpp index b51bfc6c38d637..168b2e6f7a96e2 100644 --- a/src/coreclr/jit/fgdiagnostic.cpp +++ b/src/coreclr/jit/fgdiagnostic.cpp @@ -3331,6 +3331,12 @@ void Compiler::fgDebugCheckFlagsHelper(GenTree* tree, GenTreeFlags actualFlags, // GenTreeFlags flagsToCheck = ~GTF_GLOB_REF & ~GTF_ORDER_SIDEEFF; + if (tree->isIndir() && tree->AsIndir()->Addr()->IsIconHandle(GTF_ICON_FTN_ADDR)) + { + // IND(ICON_FTN_ADDR) may or may not have GTF_IND_INVARIANT flag. + flagsToCheck &= ~GTF_IND_INVARIANT; + } + if ((actualFlags & ~expectedFlags & flagsToCheck) != 0) { // Print the tree so we can see it in the log.