From 44fdcd423a82a968d6c1336f4ef2967130874797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 15 Aug 2024 10:23:59 +0200 Subject: [PATCH] Avoid compiler crash when `UsageBasedMetadataGenerationOptions.CompleteTypesOnly` is specified Fixes #106439. This is an unsupported flag that allows generating unusable metadata for type members that would have been trimmed. This is useful when troubleshooting trimming issues for people who ignore trimming warnings because it converts random `NullReferenceException` (e.g. `GetMethod` returned null and the program didn't check for it) into "Foo.Bar wasn't generated" exceptions. Because this isn't tested, we regressed this. The code that checks whether it's possible to generate the metadata for the member at all stopped working for uninstantiated generics. This check is needed to deal with invalid input IL. --- .../Compiler/DependencyAnalysis/TypeMetadataNode.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeMetadataNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeMetadataNode.cs index 87a2c829c0269..6ae29da0e6d22 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeMetadataNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeMetadataNode.cs @@ -77,9 +77,11 @@ public override IEnumerable GetStaticDependencies(NodeFacto { try { - // Make sure we're not adding a method to the dependency graph that is going to - // cause trouble down the line. This entire type would not actually load on CoreCLR anyway. - LibraryRootProvider.CheckCanGenerateMethod(method); + // Spot check by parsing signature. + // Previously we had LibraryRootProvider.CheckCanGenerateMethod(method) here, but that one + // expects fully instantiated types and methods. We operate on definitions here. + // This is not as thorough as it could be. This option is unsupported anyway. + _ = method.Signature; } catch (TypeSystemException) {