From 43acdf98594922c6e0cf9c05f06ff276f2f3755d Mon Sep 17 00:00:00 2001
From: Vitek Karas <10670590+vitek-karas@users.noreply.github.com>
Date: Wed, 15 Mar 2023 02:38:29 -0700
Subject: [PATCH] Produce IL3000 and IL3001 from NativeAOT compiler (#83253)
This also implements the suppression of the IL3002 on the affected methods both in the NativeAOT compiler and the analyzer.
Adds single-file specific tests which are skipped for the trimmer.
Fixes: https://github.com/dotnet/runtime/issues/83088
Fixes: https://github.com/dotnet/runtime/issues/82475
---
eng/testing/tests.singlefile.targets | 2 +-
.../Dataflow/ReflectionMethodBodyScanner.cs | 21 +++++
.../TestCases/TestDatabase.cs | 5 +
.../Mono.Linker.Tests/TestCases/TestSuites.cs | 7 ++
.../RequiresAssemblyFilesAnalyzer.cs | 16 +++-
.../ILLink.Shared/TrimAnalysis/IntrinsicId.cs | 21 +++++
.../ILLink.Shared/TrimAnalysis/Intrinsics.cs | 23 +++++
.../ReflectionMethodBodyScanner.cs | 7 +-
.../RequiresAssemblyFilesAnalyzerTests.cs | 2 -
.../SingleFileTests.g.cs | 19 ++++
.../SingleFile/SingleFileIntrinsics.cs | 94 +++++++++++++++++++
.../TestCases/TestDatabase.cs | 5 +
.../Mono.Linker.Tests/TestCases/TestSuites.cs | 6 ++
13 files changed, 221 insertions(+), 7 deletions(-)
create mode 100644 src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/SingleFileTests.g.cs
create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/SingleFile/SingleFileIntrinsics.cs
diff --git a/eng/testing/tests.singlefile.targets b/eng/testing/tests.singlefile.targets
index 2252731eae8..6bbbcc7834f 100644
--- a/eng/testing/tests.singlefile.targets
+++ b/eng/testing/tests.singlefile.targets
@@ -29,7 +29,7 @@
$(CoreCLRAotSdkDir)
$(NetCoreAppCurrentTestHostSharedFrameworkPath)
$(NetCoreAppCurrentTestHostSharedFrameworkPath)
- $(NoWarn);IL1005;IL3002;IL3003
+ $(NoWarn);IL1005;IL3000;IL3001;IL3002;IL3003
partial
true
true
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
index 6e559385d27..db0fdc4a645 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
@@ -533,6 +533,27 @@ public override bool HandleCall(MethodIL callingMethodBody, MethodDesc calledMet
}
break;
+ //
+ // string System.Reflection.Assembly.Location getter
+ // string System.Reflection.AssemblyName.CodeBase getter
+ // string System.Reflection.AssemblyName.EscapedCodeBase getter
+ //
+ case IntrinsicId.Assembly_get_Location:
+ case IntrinsicId.AssemblyName_get_CodeBase:
+ case IntrinsicId.AssemblyName_get_EscapedCodeBase:
+ diagnosticContext.AddDiagnostic(DiagnosticId.AvoidAssemblyLocationInSingleFile, calledMethod.GetDisplayName());
+ break;
+
+ //
+ // string System.Reflection.Assembly.GetFile(string)
+ // string System.Reflection.Assembly.GetFiles()
+ // string System.Reflection.Assembly.GetFiles(bool)
+ //
+ case IntrinsicId.Assembly_GetFile:
+ case IntrinsicId.Assembly_GetFiles:
+ diagnosticContext.AddDiagnostic(DiagnosticId.AvoidAssemblyGetFilesInSingleFile, calledMethod.GetDisplayName());
+ break;
+
default:
throw new NotImplementedException("Unhandled intrinsic");
}
diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCases/TestDatabase.cs b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCases/TestDatabase.cs
index ec395f21795..fc9b8f26650 100644
--- a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCases/TestDatabase.cs
+++ b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCases/TestDatabase.cs
@@ -44,6 +44,11 @@ public static IEnumerable