From: Michal Strehovský Date: Tue, 7 Feb 2023 00:03:30 +0000 (+0900) Subject: Match ILScanner with CorInfoImpl (#81683) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~4198 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d666c6ecee057ab5a966374680d69569897c5ddf;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Match ILScanner with CorInfoImpl (#81683) ILScanner and the JitInterface have to be in sync wrt exceptions throw or there are problems. Fixes one of the Pri0 tests. --- diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index 7a8cb22..7c6f93b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -501,6 +501,18 @@ namespace Internal.IL // We have the canonical version of the method - find the runtime determined version. // This is simplified because we know the method is on a valuetype. Debug.Assert(targetMethod.OwningType.IsValueType); + + if (forceUseRuntimeLookup) + { + // The below logic would incorrectly resolve the lookup into the first match we found, + // but there was a compile-time ambiguity due to shared code. The correct fix should + // use the ConstrainedMethodUseLookupResult dictionary entry so that the exact + // dispatch can be computed with the help of the generic dictionary. + // We fail the compilation here to avoid bad codegen. This is not actually an invalid program. + // https://github.com/dotnet/runtimelab/issues/1431 + ThrowHelper.ThrowInvalidProgramException(); + } + MethodDesc targetOfLookup; if (_constrained.IsRuntimeDeterminedType) targetOfLookup = _compilation.TypeSystemContext.GetMethodForRuntimeDeterminedType(targetMethod.GetTypicalMethodDefinition(), (RuntimeDeterminedType)_constrained);