Fix workaround for static virtual methods (#66290)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Mon, 7 Mar 2022 15:58:30 +0000 (16:58 +0100)
committerGitHub <noreply@github.com>
Mon, 7 Mar 2022 15:58:30 +0000 (07:58 -0800)
The workaround for reflection invoking static virtual methods wasn't working around well enough. Fixes #66028.

The repro case also hit a scanning failure due to scanner not scanning a throw helper. Those are more of asserts, so add them to the collection of throw helpers to ignore.

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableMethodNode.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs
src/coreclr/tools/aot/ILCompiler/Program.cs

index 33ede22..1da18b3 100644 (file)
@@ -32,10 +32,6 @@ namespace ILCompiler.DependencyAnalysis
         {
             Debug.Assert(!factory.MetadataManager.IsReflectionBlocked(_method.GetTypicalMethodDefinition()));
 
-            // Depends on static virtual method support. Turning off reflection for now.
-            if (_method.IsVirtual && _method.Signature.IsStatic)
-                return null;
-
             DependencyList dependencies = new DependencyList();
             factory.MetadataManager.GetDependenciesDueToReflectability(ref dependencies, factory, _method);
 
index d908623..e655b20 100644 (file)
@@ -283,6 +283,10 @@ namespace ILCompiler
                     return false;
             }
 
+            // TODO: Reflection invoking static virtual methods
+            if (method.IsVirtual && method.Signature.IsStatic)
+                return false;
+
             // Everything else can go in the mapping table.
             return true;
         }
index 94bfbcc..b05cb98 100644 (file)
@@ -845,7 +845,7 @@ namespace ILCompiler
                 // Check that methods and types generated during compilation are a subset of method and types scanned
                 bool scanningFail = false;
                 DiffCompilationResults(ref scanningFail, compilationResults.CompiledMethodBodies, scanResults.CompiledMethodBodies,
-                    "Methods", "compiled", "scanned", method => !(method.GetTypicalMethodDefinition() is EcmaMethod) || method.Name == "ThrowPlatformNotSupportedException" || method.Name == "ThrowArgumentOutOfRangeException");
+                    "Methods", "compiled", "scanned", method => !(method.GetTypicalMethodDefinition() is EcmaMethod) || method.Name == "ThrowPlatformNotSupportedException" || method.Name == "ThrowArgumentOutOfRangeException" || method.Name == "ThrowArgumentException");
                 DiffCompilationResults(ref scanningFail, compilationResults.ConstructedEETypes, scanResults.ConstructedEETypes,
                     "EETypes", "compiled", "scanned", type => !(type.GetTypeDefinition() is EcmaType));