From fea626a549f2729b795e972c40c44d526a398a99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 30 Jan 2023 20:52:26 +0900 Subject: [PATCH] More thoroughly check for function pointers (#81344) Fixes #81117. --- .../Compiler/DependencyAnalysis/ReflectedFieldNode.cs | 14 ++++++++++---- .../Compiler/DependencyAnalysis/ReflectionInvokeMapNode.cs | 11 ++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectedFieldNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectedFieldNode.cs index f4cd0c8..2c3378b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectedFieldNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectedFieldNode.cs @@ -96,11 +96,17 @@ namespace ILCompiler.DependencyAnalysis { // Runtime reflection stack needs to obtain the type handle of the field // (but there's no type handles for function pointers) - TypeDesc fieldTypeToCheck = _field.FieldType; - while (fieldTypeToCheck.IsParameterizedType) - fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType; + static bool ContainsFunctionPointers(TypeDesc type) + { + if (type.IsParameterizedType) + return ContainsFunctionPointers(((ParameterizedType)type).ParameterType); + foreach (TypeDesc instArg in type.Instantiation) + if (ContainsFunctionPointers(instArg)) + return true; + return type.IsFunctionPointer; + } - if (!fieldTypeToCheck.IsFunctionPointer) + if (!ContainsFunctionPointers(_field.FieldType)) dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field"); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectionInvokeMapNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectionInvokeMapNode.cs index d0c340a..b541f52 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectionInvokeMapNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectionInvokeMapNode.cs @@ -80,7 +80,16 @@ namespace ILCompiler.DependencyAnalysis // Function pointers are not supported yet. // https://github.com/dotnet/runtime/issues/71883 - if (type.IsFunctionPointer) + static bool ContainsFunctionPointers(TypeDesc type) + { + if (type.IsParameterizedType) + return ContainsFunctionPointers(((ParameterizedType)type).ParameterType); + foreach (TypeDesc instArg in type.Instantiation) + if (ContainsFunctionPointers(instArg)) + return true; + return type.IsFunctionPointer; + } + if (ContainsFunctionPointers(type)) return; TypeDesc canonType = type.ConvertToCanonForm(CanonicalFormKind.Specific); -- 2.7.4