From d1e402c45152a9186fe6a9a25468171f39dec1e0 Mon Sep 17 00:00:00 2001 From: jcouv Date: Thu, 2 Nov 2017 14:15:48 -0700 Subject: [PATCH 01/51] Add IL verification with ILVerify in addition to PEVerify --- .../Test/Emit/Attributes/AttributeTests.cs | 2 +- .../Attributes/AttributeTests_Assembly.cs | 8 +- .../Attributes/AttributeTests_IsByRefLike.cs | 2 +- .../Attributes/AttributeTests_StructLayout.cs | 6 +- .../AttributeTests_WellKnownAttributes.cs | 4 +- .../InternalsVisibleToAndStrongNameTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenAsyncEHTests.cs | 6 +- .../Emit/CodeGen/CodeGenAsyncSpillTests.cs | 6 +- .../Emit/CodeGen/CodeGenDeconstructTests.cs | 1 - .../Test/Emit/CodeGen/CodeGenDynamicTests.cs | 2 +- .../Emit/CodeGen/CodeGenIncrementTests.cs | 3 +- .../Test/Emit/CodeGen/CodeGenIterators.cs | 2 +- .../CodeGen/CodeGenOverridingAndHiding.cs | 2 +- .../Test/Emit/CodeGen/CodeGenScriptTests.cs | 2 +- .../Emit/CodeGen/CodeGenStructsAndEnum.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 13 +-- .../Test/Emit/CodeGen/CodeGenTupleTest.cs | 1 + .../Test/Emit/CodeGen/DestructorTests.cs | 2 +- .../CSharp/Test/Emit/CodeGen/UnsafeTests.cs | 6 +- .../Test/Emit/Emit/CompilationEmitTests.cs | 2 +- .../AssemblyReferencesTests.cs | 2 +- .../EditAndContinueStateMachineTests.cs | 8 +- .../Test/Emit/Emit/EmitMetadataTests.cs | 2 +- .../CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs | 18 ++-- src/Test/Utilities/Portable/CommonTestBase.cs | 32 ++++++- .../Utilities/Portable/ExceptionHelper.cs | 5 +- .../Desktop/DesktopRuntimeEnvironment.cs | 85 +++++++++++++++++-- 27 files changed, 161 insertions(+), 65 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs index 7893c930b6e7c..5d9893d840005 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs @@ -7613,7 +7613,7 @@ class X: Attribute { } "; - CompileAndVerifyWithMscorlib40(source5, references: new[] { comp1, comp2 }); + CompileAndVerifyWithMscorlib40(source5, references: new[] { comp1, comp2 }, verify: Verification.ClassLoadGeneral); // Multiple from PE, multiple from Source var source6 = @" diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index fd17c33c073a6..8c711a74fe0df 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -296,7 +296,7 @@ public void MismatchedSurrogateInAssemblyCultureAttribute() string s = @"[assembly: System.Reflection.AssemblyCultureAttribute(""\uD800"")]"; var comp = CreateCompilation(s, options: TestOptions.ReleaseDll); - CompileAndVerify(comp, verify: Verification.Fails, symbolValidator: m => + CompileAndVerify(comp, verify: Verification.InvalidLocale, symbolValidator: m => { var utf8 = new System.Text.UTF8Encoding(false, false); Assert.Equal(utf8.GetString(utf8.GetBytes("\uD800")), m.ContainingAssembly.Identity.CultureName); @@ -654,7 +654,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Fails, + CompileAndVerify(compilation, verify: Verification.Skipped, manifestResources: hash_resources, validator: (peAssembly) => { @@ -683,7 +683,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Fails, + CompileAndVerify(compilation, verify: Verification.Skipped, manifestResources: hash_resources, validator: (peAssembly) => { @@ -716,7 +716,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Fails, + CompileAndVerify(compilation, verify: Verification.Skipped, manifestResources: hash_resources, validator: (peAssembly) => { diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index ffdb569013aba..15f31094b1f3a 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -953,7 +953,7 @@ public ref struct NotTypedReference { } }"; var compilation1 = CreateEmptyCompilation(source1, assemblyName: GetUniqueName()); - CompileAndVerify(compilation1, verify: Verification.Fails, symbolValidator: module => + CompileAndVerify(compilation1, verify: Verification.FailsPeVerify, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("System.TypedReference"); AssertReferencedIsByRefLike(type, hasObsolete: false); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs index f14a26db0fc46..fdcd33d9b1dee 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs @@ -211,10 +211,10 @@ class Structs }; CompileAndVerify(verifiable, assemblyValidator: validator); - CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.Fails); + CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.ClassLayout); // CLR limitation on type size, not a RefEmit bug: - CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.Fails); + CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.ClassLayout); } [Fact] @@ -332,7 +332,7 @@ public class C : B } "; // type C can't be loaded - CompileAndVerify(source, verify: Verification.Fails); + CompileAndVerify(source, verify: Verification.TypeLoadFailed); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs index 95d5c49160798..d2a05382a728e 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs @@ -3605,7 +3605,7 @@ public static int Main () // the resulting code does not need to verify // This is consistent with Dev10 behavior - CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.Fails, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); + CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.UnableToResolveToken, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); } [Fact, WorkItem(544507, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544507")] @@ -5552,7 +5552,7 @@ public static void Main() {} // Dev10 Runtime Exception: // Unhandled Exception: System.TypeLoadException: Windows Runtime types can only be declared in Windows Runtime assemblies. - var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.Fails, targetFramework: TargetFramework.Mscorlib40); + var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed, targetFramework: TargetFramework.Mscorlib40); } #endregion diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index 15ce7c725f4c2..bb72de0eb541e 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2592,7 +2592,7 @@ static void Main() CompileAndVerify(ca); var cb = CreateCompilation(sourceB, options: TestOptions.ReleaseExe, assemblyName: "X", references: new[] { new CSharpCompilationReference(ca) }, parseOptions: parseOptions); - CompileAndVerify(cb, expectedOutput: "42").Diagnostics.Verify(); + CompileAndVerify(cb, expectedOutput: "42", verify: Verification.IVT).Diagnostics.Verify(); } [WorkItem(1095618, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095618")] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs index 6454ef8e7eb54..58609ae5f867c 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs @@ -19,10 +19,10 @@ public CodeGenAsyncEHTests() { } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes) { references = (references != null) ? references.Concat(s_asyncRefs) : s_asyncRefs; - return base.CompileAndVerify(source, targetFramework: TargetFramework.Empty, expectedOutput: expectedOutput, references: references, options: options); + return base.CompileAndVerify(source, targetFramework: TargetFramework.Empty, expectedOutput: expectedOutput, references: references, options: options, verify: verify); } [Fact] @@ -1837,7 +1837,7 @@ public static void Main() hello 2 "; - CompileAndVerify(source, expectedOutput: expected); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.LeaveIntoTry); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs index ee5e6afba8773..1c3b93918cec1 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs @@ -17,9 +17,9 @@ public CodeGenAsyncSpillTests() { } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes) { - return base.CompileAndVerify(source, expectedOutput: expectedOutput, references: references, options: options); + return base.CompileAndVerify(source, expectedOutput: expectedOutput, references: references, options: options, verify: verify); } [Fact] @@ -2476,7 +2476,7 @@ public static void Main() 2 0 "; - CompileAndVerify(source, expectedOutput: expected); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.RuntimeArgumentHandle); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs index a29b2f307a7a1..31a8a0e69b3a6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs @@ -97,7 +97,6 @@ public void Deconstruct(out int a, out string b) var right = tree.GetRoot().DescendantNodes().OfType().Single(); Assert.Equal(@"new C()", right.ToString()); Assert.Equal("C", model.GetTypeInfo(right).Type.ToTestDisplayString()); - Assert.Equal("C", model.GetTypeInfo(right).ConvertedType.ToTestDisplayString()); Assert.Equal(ConversionKind.Identity, model.GetConversion(right).Kind); }; diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs index b9bfcb6036a1b..2c1404a5b4cce 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs @@ -9600,7 +9600,7 @@ .locals init (int V_0, //a IL_0066: callvirt ""void <>A{00000002}.Invoke(System.Runtime.CompilerServices.CallSite, ref int, object)"" IL_006b: ret } -"); +", verify: Verification.PassesPeVerify | Verification.FailsIlVerify); // ILVerify doesn't support TypedReference } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs index 8628016210cc7..874f9252d488f 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs @@ -3,6 +3,7 @@ using System; using System.Globalization; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; +using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; @@ -1029,7 +1030,7 @@ public static void Main() } } "; - base.CompileAndVerify(source, expectedOutput: "12"). + base.CompileAndVerify(source, verify: Verification.TypedReference, expectedOutput: "12"). VerifyIL("Test.Main", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs index 7d614567fc461..2849921d4500b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs @@ -2383,7 +2383,7 @@ public System.Collections.IEnumerable SomeNumbers() }"; // The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available. var compilation = CreateEmptyCompilation(new[] { Parse(source), Parse(corlib) }); - var verifier = CompileAndVerify(compilation, verify: Verification.Fails); + var verifier = CompileAndVerify(compilation, verify: Verification.TypeLoadFailed); verifier.VerifyDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1)); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs index 4b778a7c1c901..51ebd19b63a62 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs @@ -2449,7 +2449,7 @@ public static void Main() // from assembly 'Dev10, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' // is overriding a method that is not visible from that assembly. - CompileAndVerify(outerCompilation, verify: Verification.Fails).VerifyIL("Test.Main", @" + CompileAndVerify(outerCompilation, verify: Verification.FailsPeVerify | Verification.PassesIlVerify).VerifyIL("Test.Main", @" { // Code size 65 (0x41) .maxstack 4 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs index 065508fff3ae2..69b731ba8286d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs @@ -553,7 +553,7 @@ public void SubmissionEntryPoint() "s0.dll", SyntaxFactory.ParseSyntaxTree(source0, options: TestOptions.Script), references); - var verifier = CompileAndVerify(s0, verify: Verification.Fails); + var verifier = CompileAndVerify(s0, verify: Verification.BadName); var methodData = verifier.TestData.GetMethodData(""); Assert.Equal("System.Threading.Tasks.Task", ((MethodSymbol)methodData.Method).ReturnType.ToDisplayString()); methodData.VerifyIL( diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index d6272904c3972..5dff713de1a31 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -1277,7 +1277,7 @@ public static void Main() } "; - var compilation = CompileAndVerify(source, expectedOutput: "11"); + var compilation = CompileAndVerify(source, expectedOutput: "11", verify: Verification.InvalidProgramVararg); compilation.VerifyIL("D.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 78a6ec89c5f97..30b48d8617885 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -4345,7 +4345,7 @@ public static void M() Callee3(default(T), default(T)); } } -", verify: Verification.Fails, options: TestOptions.ReleaseExe); +", verify: Verification.TypeDevNotNil, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 297 (0x129) @@ -4478,7 +4478,7 @@ public static void M() Callee3(); } } -", verify: Verification.Fails, options: TestOptions.ReleaseExe); +", verify: Verification.TypeDevNotNil, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 34 (0x22) @@ -5159,7 +5159,7 @@ static void Test(in object r) } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"hi", verify: Verification.Fails); + var compilation = CompileAndVerify(source, expectedOutput: @"hi", verify: Verification.UnexpectedTypeOnStack); compilation.VerifyIL("Program.Main(string[])", @" @@ -5245,7 +5245,7 @@ static void Test(in T r) } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.Fails); + var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.UnexpectedTypeOnStack); var expectedIL = @" { @@ -5266,7 +5266,7 @@ .maxstack 2 compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); // expect the same IL in the compat case since direct references are required and must be emitted with "readonly.", even though unverifiable - compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.Fails, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); + compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.UnexpectedTypeOnStack, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); } @@ -10444,7 +10444,7 @@ static void Main() Diagnostic(ErrorCode.WRN_ExternMethodNoImplementation, "Goo").WithArguments("Test.Goo()")); // NOTE: the resulting IL is unverifiable, but not an error for compat reasons - CompileAndVerify(comp, verify: Verification.Fails).VerifyIL("Test.Main", + CompileAndVerify(comp, verify: Verification.TypeLoadFailed).VerifyIL("Test.Main", @" { // Code size 11 (0xb) @@ -13293,6 +13293,7 @@ private void PrintArgList(ArgIterator args) "; var compilation = CompileAndVerify( source, + verify: Verification.InvalidProgramVararg, expectedOutput: @"Inside - TestVarArgs::ctor (__arglist) Inside - TestVarArgs::ctor (__arglist) System.Int32 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index 261b3fd33f3b8..ead2f7d3af08e 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Linq; using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; using System.Text; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE; diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs index 5a3d670081f55..f4f25a13688b3 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs @@ -694,7 +694,7 @@ public class B : A Diagnostic(ErrorCode.WRN_FinalizeMethod, "Finalize")); // We produce unverifiable code here as per bug resolution (compat concerns, not common case). - CompileAndVerify(compilation, verify: Verification.Fails).VerifyIL("B.Finalize", + CompileAndVerify(compilation, verify: Verification.TypeLoadFailed).VerifyIL("B.Finalize", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index 39a975b6c777d..a481a01dd4f97 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -10214,7 +10214,7 @@ public static void Main() } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails).VerifyDiagnostics(); + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.Passes).VerifyDiagnostics(); } [WorkItem(545026, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545026")] @@ -10228,7 +10228,7 @@ class C unsafe int* p = (int*)2; } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).VerifyDiagnostics( // (4,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); @@ -10245,7 +10245,7 @@ class C int x = 1; } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).VerifyDiagnostics( // (5,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 70419535560b9..07c09127ffd4e 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4644,7 +4644,7 @@ public void Bug769741() { var comp = CreateEmptyCompilation("", new[] { TestReferences.SymbolsTests.netModule.x64COFF }, options: TestOptions.DebugDll); // modules not supported in ref emit - CompileAndVerify(comp, verify: Verification.Fails); + CompileAndVerify(comp, verify: Verification.BadFormat); Assert.NotSame(comp.Assembly.CorLibrary, comp.Assembly); comp.GetSpecialType(SpecialType.System_Int32); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs index 3cbf99454d133..d1e5d807eedef 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs @@ -477,7 +477,7 @@ class C var compilation0 = CreateEmptyCompilation(src0, new[] { MscorlibRef, ref01, ref11 }, assemblyName: "C", options: TestOptions.DebugDll); var compilation1 = compilation0.WithSource(src1).WithReferences(new[] { MscorlibRef, ref02, ref12 }); - var v0 = CompileAndVerify(compilation0); + var v0 = CompileAndVerify(compilation0, verify: Verification.FullNames); var f0 = compilation0.GetMember("C.F"); var f1 = compilation1.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs index 45f2860895387..fd504d84cfad8 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs @@ -4969,7 +4969,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); @@ -5028,7 +5028,7 @@ public async Task F() // older versions of mscorlib don't contain IteratorStateMachineAttribute Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5092,7 +5092,7 @@ public async Task F() Assert.NotNull(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5193,7 +5193,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs index c98bb3059ec3f..708df6a2af97e 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs @@ -174,7 +174,7 @@ public class Test : Class2 { } "; - CompileAndVerifyWithMscorlib40(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, assemblyValidator: (assembly) => + CompileAndVerifyWithMscorlib40(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, verify: Verification.NotImplemented, assemblyValidator: (assembly) => { var refs2 = assembly.Modules[0].ReferencedAssemblies.Select(r => r.Name); Assert.Equal(2, refs2.Count()); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs index c6a86df01f718..01daea6a90755 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs @@ -1661,12 +1661,12 @@ .maxstack 2 } "; - var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator); + var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.InvalidProgramVararg); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); - verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator); + verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.InvalidProgramVararg); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); @@ -1775,9 +1775,9 @@ interface UsePia5 : ITest29 Assert.Equal(VarianceKind.None, t7.Variance); }; - CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.Fails); + CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed); - CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.Fails); + CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed); } [Fact] @@ -4704,11 +4704,11 @@ public void M1() var compilation3 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.Fails); + CompileAndVerify(compilation3, verify: Verification.TypeLoadFailed); var compilation4 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.Fails); + CompileAndVerify(compilation4, verify: Verification.TypeLoadFailed); } [Fact] @@ -5181,11 +5181,11 @@ public void M1() var compilation3 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.Fails); + CompileAndVerify(compilation3, verify: Verification.TypeLoadFailed); var compilation4 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.Fails); + CompileAndVerify(compilation4, verify: Verification.TypeLoadFailed); } [ConditionalFact(typeof(ClrOnly), Reason = ConditionalSkipReason.NoPiaNeedsDesktop)] @@ -5403,7 +5403,7 @@ static string MyEvent02Handler(string arg) { var app_compilation = CreateCompilation(App_cs, new[] { NetImpl_ref, IEvent_ref, CSharpRef }, options: TestOptions.ReleaseExe, assemblyName: "App"); - CompileAndVerify(app_compilation, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, + CompileAndVerify(app_compilation, verify: Verification.NoPia, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, expectedOutput: @"E01 E02"); } diff --git a/src/Test/Utilities/Portable/CommonTestBase.cs b/src/Test/Utilities/Portable/CommonTestBase.cs index a142dd2c273cc..b7242ccc8a29e 100644 --- a/src/Test/Utilities/Portable/CommonTestBase.cs +++ b/src/Test/Utilities/Portable/CommonTestBase.cs @@ -23,11 +23,37 @@ namespace Microsoft.CodeAnalysis.Test.Utilities { + [Flags] public enum Verification { - Passes = 0, - Fails, - Skipped + Skipped = 0, + + PassesPeVerify = 1 << 0, + PassesIlVerify = 1 << 1, + FailsPeVerify = 1 << 2, + FailsIlVerify = 1 << 3, + + Passes = PassesPeVerify | PassesIlVerify, + Fails = FailsPeVerify | FailsIlVerify, + + IVT = PassesPeVerify | FailsIlVerify, // ILVerify is case-sensitive in IVT + FullNames = PassesPeVerify, // ILVerify uses simple names instead of full names + TypedReference = PassesPeVerify | FailsIlVerify, // ILVerify doesn't support TypedReference + InvalidProgramVararg = PassesPeVerify | FailsIlVerify, // ILVerify complains about InvalidProgramVararg + ClassLoadGeneral = PassesPeVerify | FailsIlVerify, // ILVerify complains about ClassLoadGeneral + NotImplemented = PassesPeVerify | FailsIlVerify, // ILVerify has some un-implemented cases in EcmaModule.GetType + NoPia = PassesPeVerify | FailsIlVerify, // ILVerify doesn't do NoPia unification + RuntimeArgumentHandle = PassesPeVerify | FailsIlVerify, // ILVerify reports: RuntimeArgumentHandle not supported in .NET Core + LeaveIntoTry = PassesPeVerify | FailsIlVerify, // ILVerify reports: Leave into try block. + + TypeLoadFailed = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain type load failed + UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: Unexpected type on the stack. + InvalidLocale = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about invalid locale string + UnableToResolveToken = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about "unable to resolve token" + TypeDevNotNil = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. + ClassLayout = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. + BadName = FailsPeVerify | PassesIlVerify, // PEVerify complains about: Assembly name contains leading spaces or path or extension. + BadFormat = FailsPeVerify | PassesIlVerify, // PEVerify complains about: An attempt was made to load a program with an incorrect format. } /// diff --git a/src/Test/Utilities/Portable/ExceptionHelper.cs b/src/Test/Utilities/Portable/ExceptionHelper.cs index 4c6c768dd87d1..a0e5f725d30b9 100644 --- a/src/Test/Utilities/Portable/ExceptionHelper.cs +++ b/src/Test/Utilities/Portable/ExceptionHelper.cs @@ -21,11 +21,12 @@ internal static string GetMessageFromResult(IEnumerable diagnostics, return sb.ToString(); } - internal static string GetMessageFromResult(string output, string exePath) + internal static string GetMessageFromResult(string output, string exePath, bool isIlVerify = false) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); - sb.Append("PeVerify failed for assembly '"); + string tool = isIlVerify ? "IlVerify" : "PeVerify"; + sb.Append($"{tool} failed for assembly '"); sb.Append(exePath); sb.AppendLine("':"); sb.AppendLine(output); diff --git a/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs index 85a3c951aad90..19b048f4c3908 100644 --- a/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -5,13 +5,17 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeGen; using Microsoft.CodeAnalysis.Emit; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Roslyn.Utilities; @@ -237,7 +241,7 @@ public int Execute(string moduleName, string[] args, string expectedOutput) { var emitData = GetEmitData(); emitData.RuntimeData.ExecuteRequested = true; - var resultCode = emitData.Manager.Execute(moduleName, args, expectedOutput?.Length, out var output); + var resultCode = emitData.Manager.Execute(moduleName, args, expectedOutputLength: expectedOutput?.Length, out var output); if (expectedOutput != null && expectedOutput.Trim() != output.Trim()) { @@ -289,37 +293,100 @@ public IList GetAllModuleData() return GetEmitData().AllModuleData; } - public void Verify(Verification verification) +#if NET461 + private class Resolver : ILVerify.ResolverBase { - // Verification is only done on windows desktop - if (!ExecutionConditionUtil.IsWindowsDesktop) + private Dictionary> imagesByName = new Dictionary>(); + + internal Resolver(EmitData emitData) { - return; + foreach (var module in emitData.AllModuleData) + { + string name = module.SimpleName; + + var image = name == "mscorlib" + ? TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() + : module.Image; + + imagesByName.Add(name, image); + } } + protected override PEReader ResolveCore(AssemblyName name) + { + if (imagesByName.TryGetValue(name.Name, out var image)) + { + return new PEReader(image); + } + + return null; + } + } +#endif + + public void Verify(Verification verification) + { if (verification == Verification.Skipped) { return; } - var shouldSucceed = verification == Verification.Passes; var emitData = GetEmitData(); + +#if NET461 + // IL Verify + var resolver = new Resolver(emitData); + var verifier = new ILVerify.Verifier(resolver); + if (emitData.AllModuleData.Any(m => m.SimpleName == "mscorlib")) + { + verifier.SetSystemModuleName(new AssemblyName("mscorlib")); + } + else + { + // auto-detect which module is the "corlib" + foreach (var module in emitData.AllModuleData) + { + var name = new AssemblyName(module.SimpleName); + var metadataReader = resolver.Resolve(name).GetMetadataReader(); + if (metadataReader.AssemblyReferences.Count == 0) + { + verifier.SetSystemModuleName(name); + } + } + } + + var result = verifier.Verify(resolver.Resolve(new AssemblyName(emitData.MainModule.FullName))); + if (result.Count() > 0) + { + if ((verification & Verification.PassesIlVerify) != 0) + { + throw new Exception("IL Verify failed"); + } + } + else if ((verification & Verification.FailsIlVerify) != 0) + { + throw new Exception("IL Verify succeeded unexpectedly"); + } +#endif + + // PE Verify try { emitData.RuntimeData.PeverifyRequested = true; emitData.Manager.PeVerifyModules(new[] { emitData.MainModule.FullName }, throwOnError: true); - if (!shouldSucceed) + if ((verification & Verification.FailsPeVerify) != 0) { - throw new Exception("Verification succeeded unexpectedly"); + throw new Exception("PE Verify succeeded unexpectedly"); } } catch (RuntimePeVerifyException ex) { - if (shouldSucceed) + if ((verification & Verification.PassesPeVerify) != 0) { throw new Exception("Verification failed", ex); } } + } public string[] VerifyModules(string[] modulesToVerify) From 70d3ab8a0d0c0c3bd6c3a7dd7141f01b5ac0810d Mon Sep 17 00:00:00 2001 From: jcouv Date: Thu, 22 Mar 2018 16:32:38 -0700 Subject: [PATCH 02/51] Annotating more tests --- .../Test/Emit/Attributes/AttributeTests.cs | 2 +- .../Attributes/AttributeTests_Assembly.cs | 8 ++- .../Emit/Attributes/AttributeTests_Dynamic.cs | 4 +- .../Attributes/AttributeTests_IsByRefLike.cs | 4 +- .../Attributes/AttributeTests_IsUnmanaged.cs | 8 +-- .../Attributes/AttributeTests_RefReadOnly.cs | 3 +- .../Attributes/AttributeTests_Synthesized.cs | 3 +- .../Emit/CodeGen/CodeGenExprLambdaTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenMscorlib.cs | 7 ++- .../CodeGenShortCircuitOperatorTests.cs | 3 +- .../Emit/CodeGen/CodeGenStructsAndEnum.cs | 10 ++-- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 8 +-- .../CSharp/Test/Emit/CodeGen/SwitchTests.cs | 4 +- .../CSharp/Test/Emit/CodeGen/UnsafeTests.cs | 4 +- src/Test/Utilities/Portable/CommonTestBase.cs | 1 - .../Desktop/DesktopRuntimeEnvironment.cs | 49 ++++++++++--------- 16 files changed, 69 insertions(+), 51 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs index 5d9893d840005..7893c930b6e7c 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs @@ -7613,7 +7613,7 @@ class X: Attribute { } "; - CompileAndVerifyWithMscorlib40(source5, references: new[] { comp1, comp2 }, verify: Verification.ClassLoadGeneral); + CompileAndVerifyWithMscorlib40(source5, references: new[] { comp1, comp2 }); // Multiple from PE, multiple from Source var source6 = @" diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 8c711a74fe0df..1bd41f56d06bc 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -296,7 +296,8 @@ public void MismatchedSurrogateInAssemblyCultureAttribute() string s = @"[assembly: System.Reflection.AssemblyCultureAttribute(""\uD800"")]"; var comp = CreateCompilation(s, options: TestOptions.ReleaseDll); - CompileAndVerify(comp, verify: Verification.InvalidLocale, symbolValidator: m => + // PROTOTYPE(verification) Can't verify with invalid culture + CompileAndVerify(comp, verify: Verification.Skipped, symbolValidator: m => { var utf8 = new System.Text.UTF8Encoding(false, false); Assert.Equal(utf8.GetString(utf8.GetBytes("\uD800")), m.ContainingAssembly.Identity.CultureName); @@ -540,6 +541,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, + verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token manifestResources: hash_resources, validator: (peAssembly) => { @@ -569,6 +571,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, + verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token manifestResources: hash_resources, validator: (peAssembly) => { @@ -598,6 +601,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, + verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token manifestResources: hash_resources, validator: (peAssembly) => { @@ -627,6 +631,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, + verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token manifestResources: hash_resources, validator: (peAssembly) => { @@ -757,6 +762,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module_Comp.EmitToImageReference() }); CompileAndVerify(compilation, + verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token validator: (peAssembly) => { var peReader = peAssembly.ManifestModule.GetMetadataReader(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index 45f099e9a4d2f..b5864ee4fc608 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1150,7 +1150,7 @@ static void Main() comp = CreateEmptyCompilation(source1, references: new[] { ref0, SystemCoreRef }); comp.VerifyDiagnostics(); // Make sure we emit without errors when System.Boolean is missing. - CompileAndVerify(comp, verify: Verification.Fails); + CompileAndVerify(comp, verify: Verification.FailsPeVerify); // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException+TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, 71b2955e-695c-48f1-86db-7ace51a3dc36, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null } [Fact] @@ -1184,7 +1184,7 @@ static void Main() comp = CreateEmptyCompilation(source1, references: new[] { ref0, SystemCoreRef }); comp.VerifyDiagnostics(); // Make sure we emit without errors when System.Boolean is missing. - CompileAndVerify(comp, verify: Verification.Fails); + CompileAndVerify(comp, verify: Verification.FailsPeVerify); // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException+TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, 71b2955e-695c-48f1-86db-7ace51a3dc36, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index 15f31094b1f3a..1df802b76e494 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -426,8 +426,8 @@ public class Test { public ref struct S1{} }"; - - CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + // PROTOTYPE(verification) + CompileAndVerify(code, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs index 8cfde01329238..c390f384485ed 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs @@ -251,8 +251,8 @@ public class Test public void M() where T : unmanaged { } } "; - - CompileAndVerify(text, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + // PROTOTYPE(verification) + CompileAndVerify(text, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); @@ -277,8 +277,8 @@ public class Test where T : unmanaged { } "; - - CompileAndVerify(text, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + // PROTOTYPE(verification) + CompileAndVerify(text, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test`1").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs index 44a78a9196b6b..bd6da4c324c7b 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs @@ -1153,7 +1153,8 @@ public class Test public void M(in int x) { } }"; - CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + // PROTOTYPE(verification) + CompileAndVerify(code, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { AssertNoIsReadOnlyAttributeExists(module.ContainingAssembly); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index c7ddc3eea5195..17d4da27271ae 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -850,7 +850,8 @@ public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(Ou } else { - CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => + // PROTOTYPE(verification) + CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Skipped, symbolValidator: module => { var assemblyAttributes = module.ContainingAssembly.GetAttributes(); Assert.Equal(0, assemblyAttributes.Length); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs index ea3602cad6056..493512dcf53b6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs @@ -3114,7 +3114,7 @@ public static void Main() var c = CompileAndVerifyUtil(text, options: TestOptions.UnsafeReleaseDll, - verify: Verification.Fails); + verify: Verification.FailsPeVerify | Verification.PassesIlVerify); // PROTOTYPE(verification) c.VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs index c1d1d81b2c9c4..5d4bdf8dcd087 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs @@ -739,7 +739,9 @@ void Main() //IMPORTANT: we should NOT delegate E1.GetHashCode() to int.GetHashCode() // it is entirely possible that Enum.GetHashCode and int.GetHashCode // have different implementations - CompileAndVerify(comp, verify: Verification.Fails). + + // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException + TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, 699fa24e-4ae5-4965-b7a7-166da051a9a9, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + CompileAndVerify(comp, verify: Verification.FailsPeVerify). VerifyIL("program.Main()", @" { @@ -866,7 +868,8 @@ void Main() // but see the bug see VSW #396011, JIT needs references when loading // fields of certain clr-ambiguous structs (only possible when building mscorlib) - CompileAndVerify(comp, verify: Verification.Fails). + // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException+TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, cb9df1f8-9e67-4084-a523-059b000cf4b6, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + CompileAndVerify(comp, verify: Verification.FailsPeVerify). VerifyIL("System.IntPtr..ctor(int)", @" { // Code size 10 (0xa) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs index ae47fd543c5d3..9077b8a737d57 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs @@ -5227,7 +5227,8 @@ public RefLike M() public ref struct RefLike{} } "; - var verifier = CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- + // PROTOTYPE(verification) Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var verifier = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- M --- ---"); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index 5dff713de1a31..5da5cd2aa58a0 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -255,7 +255,8 @@ static void Main(string[] args) } } "; - var compilation = CompileAndVerify(source, expectedOutput: @""); + // PROTOTYPE(verification) Unexpected type on the stack. + var compilation = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, expectedOutput: @""); compilation.VerifyIL("S1.Equals(object)", @" @@ -444,7 +445,8 @@ static void Main() } } "; - var compilation = CompileAndVerify(source, expectedOutput: @" + // PROTOTYPE(verification) Unexpected type on the stack. + var compilation = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, expectedOutput: @" Abc 255 q"); @@ -2361,8 +2363,8 @@ static void Main(string[] args) } "; - - var compilation = CompileAndVerify(source, expectedOutput: "0"); + // PROTOTYPE(verification) Unexpected type on the stack. + var compilation = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, expectedOutput: "0"); compilation.VerifyIL("Program.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 30b48d8617885..643238333290b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -72,7 +72,8 @@ static void Main(object[] args) Console.WriteLine((((DoubleAndStruct)args[0]).y).x); } }"; - var result = CompileAndVerify(source, options: TestOptions.DebugDll); + // PROTOTYPE(verification) Unexpected type on the stack. + var result = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -159,7 +160,8 @@ static void Main(object[] args) Console.WriteLine(((((OuterStruct)args[0]).z).y).x); } }"; - var result = CompileAndVerify(source, options: TestOptions.DebugDll); + // PROTOTYPE(verification) Unexpected type on the stack. + var result = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -5159,7 +5161,7 @@ static void Test(in object r) } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"hi", verify: Verification.UnexpectedTypeOnStack); + var compilation = CompileAndVerify(source, expectedOutput: @"hi", verify: Verification.Fails); compilation.VerifyIL("Program.Main(string[])", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs index 89ff84d481719..b8cbb069cc7bf 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs @@ -4106,8 +4106,8 @@ static void Main() source: new[] { Parse(text) }, references: new[] { AacorlibRef }); - - var verifier = CompileAndVerify(comp, verify: Verification.Fails); + // PROTOTYPE(verification) + var verifier = CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.PassesIlVerify); verifier.VerifyIL("Program.Main", @" { // Code size 229 (0xe5) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index a481a01dd4f97..b2353312eb375 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -10032,8 +10032,8 @@ No overflow from (S15*)0 + sizeof(S15) No overflow from (S15*)0 + sizeof(S16) No overflow from (S16*)0 + sizeof(S15)"; } - - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: expectedOutput, verify: Verification.Fails); + // PROTOTYPE(verification) + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify | Verification.PassesIlVerify); } [Fact] diff --git a/src/Test/Utilities/Portable/CommonTestBase.cs b/src/Test/Utilities/Portable/CommonTestBase.cs index b7242ccc8a29e..2f13a96f19789 100644 --- a/src/Test/Utilities/Portable/CommonTestBase.cs +++ b/src/Test/Utilities/Portable/CommonTestBase.cs @@ -48,7 +48,6 @@ public enum Verification TypeLoadFailed = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain type load failed UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: Unexpected type on the stack. - InvalidLocale = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about invalid locale string UnableToResolveToken = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about "unable to resolve token" TypeDevNotNil = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. ClassLayout = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. diff --git a/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs index 19b048f4c3908..6edf2a8f07563 100644 --- a/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -335,37 +335,40 @@ public void Verify(Verification verification) #if NET461 // IL Verify - var resolver = new Resolver(emitData); - var verifier = new ILVerify.Verifier(resolver); - if (emitData.AllModuleData.Any(m => m.SimpleName == "mscorlib")) + if ((verification & (Verification.PassesIlVerify | Verification.FailsIlVerify)) != 0) { - verifier.SetSystemModuleName(new AssemblyName("mscorlib")); - } - else - { - // auto-detect which module is the "corlib" - foreach (var module in emitData.AllModuleData) + var resolver = new Resolver(emitData); + var verifier = new ILVerify.Verifier(resolver); + if (emitData.AllModuleData.Any(m => m.SimpleName == "mscorlib")) { - var name = new AssemblyName(module.SimpleName); - var metadataReader = resolver.Resolve(name).GetMetadataReader(); - if (metadataReader.AssemblyReferences.Count == 0) + verifier.SetSystemModuleName(new AssemblyName("mscorlib")); + } + else + { + // auto-detect which module is the "corlib" + foreach (var module in emitData.AllModuleData) { - verifier.SetSystemModuleName(name); + var name = new AssemblyName(module.SimpleName); + var metadataReader = resolver.Resolve(name).GetMetadataReader(); + if (metadataReader.AssemblyReferences.Count == 0) + { + verifier.SetSystemModuleName(name); + } } } - } - var result = verifier.Verify(resolver.Resolve(new AssemblyName(emitData.MainModule.FullName))); - if (result.Count() > 0) - { - if ((verification & Verification.PassesIlVerify) != 0) + var result = verifier.Verify(resolver.Resolve(new AssemblyName(emitData.MainModule.FullName))); + if (result.Count() > 0) { - throw new Exception("IL Verify failed"); + if ((verification & Verification.PassesIlVerify) != 0) + { + throw new Exception("IL Verify failed: \r\n" + string.Join("\r\n", result.Select(r => r.Message))); + } + } + else if ((verification & Verification.FailsIlVerify) != 0) + { + throw new Exception("IL Verify succeeded unexpectedly"); } - } - else if ((verification & Verification.FailsIlVerify) != 0) - { - throw new Exception("IL Verify succeeded unexpectedly"); } #endif From 3f8b70fb3c4f9510d0b85bf339c451902e406902 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 22 Mar 2018 06:14:12 -0700 Subject: [PATCH 03/51] Use new package with strong name --- .../Utilities/Portable/TestUtilities.csproj | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/Test/Utilities/Portable/TestUtilities.csproj diff --git a/src/Test/Utilities/Portable/TestUtilities.csproj b/src/Test/Utilities/Portable/TestUtilities.csproj new file mode 100644 index 0000000000000..064ece44bf28a --- /dev/null +++ b/src/Test/Utilities/Portable/TestUtilities.csproj @@ -0,0 +1,108 @@ + + + + + AnyCPU + AnyCPU + Library + Roslyn.Test.Utilities + true + true + netstandard1.3;$(RoslynPortableTargetFrameworks);net46 + $(DefineConstants);DNX + true + + false + + + + + + + + + + + $(DefineConstants);TEST_IOPERATION_INTERFACE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DesktopAnalyzerAssemblyLoader.cs + + + True + True + TestResource.resx + + + + + PublicResXFileCodeGenerator + TestResource.Designer.cs + Roslyn.Test.Utilities + + + + + + + + + + + + + + + + + + + + + + + + From bf116d9db48ae143c55ff499a6b7e2d996bac752 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 10:48:47 -0800 Subject: [PATCH 04/51] Fix a couple more tests --- .../CSharp/Test/Emit/CodeGen/UnsafeTests.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index 680b345aa90b2..b54fd3a8eb70b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -10328,7 +10328,10 @@ public static void Main() } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.Passes).VerifyDiagnostics(); + // PEVerify: + // [ : ChannelServices::.cctor][mdToken=0x6000005][offset 0x0000000C][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack. + // [ : ChannelServices::GetPrivateContextsPerfCounters][mdToken= 0x6000002][offset 0x00000002][found Native Int][expected unmanaged pointer] Unexpected type on the stack. + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.PassesIlVerify | Verification.FailsPeVerify).VerifyDiagnostics(); } [WorkItem(545026, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545026")] @@ -10342,7 +10345,9 @@ class C unsafe int* p = (int*)2; } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).VerifyDiagnostics( + // PEVerify: + // [ : C::.ctor][mdToken=0x6000001][offset 0x0000000A][found Native Int][expected unmanaged pointer] Unexpected type on the stack. + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.PassesIlVerify | Verification.FailsPeVerify).VerifyDiagnostics( // (4,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); @@ -10359,7 +10364,9 @@ class C int x = 1; } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).VerifyDiagnostics( + // PEVerify: + // [ : C::.ctor][mdToken=0x6000001][offset 0x00000003][found Native Int][expected unmanaged pointer] Unexpected type on the stack. + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.PassesIlVerify | Verification.FailsPeVerify).VerifyDiagnostics( // (5,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); From a993d0e0ac60c47070f78839ac86dcdb1865e510 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 11:44:04 -0800 Subject: [PATCH 05/51] Address some PROTOTYPE markers --- .../Attributes/AttributeTests_Assembly.cs | 17 +++++---- .../Emit/Attributes/AttributeTests_Dynamic.cs | 6 ++-- .../Attributes/AttributeTests_IsByRefLike.cs | 3 +- .../Attributes/AttributeTests_IsUnmanaged.cs | 6 ++-- .../Attributes/AttributeTests_RefReadOnly.cs | 4 +-- .../Attributes/AttributeTests_StructLayout.cs | 6 ++-- .../Attributes/AttributeTests_Synthesized.cs | 3 +- .../AttributeTests_WellKnownAttributes.cs | 4 +-- .../InternalsVisibleToAndStrongNameTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenAsyncEHTests.cs | 2 +- .../Emit/CodeGen/CodeGenAsyncSpillTests.cs | 2 +- .../Emit/CodeGen/CodeGenExprLambdaTests.cs | 3 +- .../Emit/CodeGen/CodeGenIncrementTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenIterators.cs | 2 +- .../Test/Emit/CodeGen/CodeGenMscorlib.cs | 11 +++--- .../Test/Emit/CodeGen/CodeGenScriptTests.cs | 2 +- .../CodeGenShortCircuitOperatorTests.cs | 3 +- .../Emit/CodeGen/CodeGenStructsAndEnum.cs | 11 +++--- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 18 +++++----- .../Test/Emit/CodeGen/DestructorTests.cs | 2 +- .../CSharp/Test/Emit/CodeGen/SwitchTests.cs | 6 ++-- .../CSharp/Test/Emit/CodeGen/UnsafeTests.cs | 7 ++-- .../Test/Emit/Emit/CompilationEmitTests.cs | 2 +- .../EditAndContinueStateMachineTests.cs | 8 ++--- .../Test/Emit/Emit/EmitMetadataTests.cs | 2 +- .../CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs | 18 +++++----- src/Compilers/Test/Core/CommonTestBase.cs | 36 ++++++++++--------- 27 files changed, 95 insertions(+), 93 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 766c1299fa16d..7dc094dcb59f0 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -22,8 +22,6 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests { public class AssemblyAttributeTests : CSharpTestBase { - private readonly string _netModuleName = GetUniqueName() + ".netmodule"; - [Fact] public void VersionAttribute() { @@ -300,8 +298,9 @@ public void MismatchedSurrogateInAssemblyCultureAttribute() string s = @"[assembly: System.Reflection.AssemblyCultureAttribute(""\uD800"")]"; var comp = CreateCompilation(s, options: TestOptions.ReleaseDll); - // PROTOTYPE(verification) Can't verify with invalid culture - CompileAndVerify(comp, verify: Verification.Skipped, symbolValidator: m => + // PEVerify: + // Warning: Invalid locale string. + CompileAndVerify(comp, verify: Verification.Passes, symbolValidator: m => { var utf8 = new System.Text.UTF8Encoding(false, false); Assert.Equal(utf8.GetString(utf8.GetBytes("\uD800")), m.ContainingAssembly.Identity.CultureName); @@ -545,7 +544,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token + verify: Verification.Passes, manifestResources: hash_resources, validator: (peAssembly) => { @@ -575,7 +574,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token + verify: Verification.Passes, manifestResources: hash_resources, validator: (peAssembly) => { @@ -605,7 +604,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token + verify: Verification.Passes, manifestResources: hash_resources, validator: (peAssembly) => { @@ -635,7 +634,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token + verify: Verification.Passes, manifestResources: hash_resources, validator: (peAssembly) => { @@ -766,7 +765,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module_Comp.EmitToImageReference() }); CompileAndVerify(compilation, - verify: Verification.PassesPeVerify | Verification.FailsIlVerify, // PROTOTYPE(verification): Unable to resolve token + verify: Verification.Passes, validator: (peAssembly) => { var peReader = peAssembly.ManifestModule.GetMetadataReader(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index ccf5fb8e3d4c8..9e4cdde32da7e 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1155,7 +1155,8 @@ static void Main() comp = CreateEmptyCompilation(source1, references: new[] { ref0, SystemCoreRef }); comp.VerifyDiagnostics(); // Make sure we emit without errors when System.Boolean is missing. - CompileAndVerify(comp, verify: Verification.FailsPeVerify); // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException+TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, 71b2955e-695c-48f1-86db-7ace51a3dc36, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + // PEVerify: Type load failed. + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); } [Fact] @@ -1189,7 +1190,8 @@ static void Main() comp = CreateEmptyCompilation(source1, references: new[] { ref0, SystemCoreRef }); comp.VerifyDiagnostics(); // Make sure we emit without errors when System.Boolean is missing. - CompileAndVerify(comp, verify: Verification.FailsPeVerify); // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException+TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, 71b2955e-695c-48f1-86db-7ace51a3dc36, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + // PEVerify: Type load failed. + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index 00df4016577f6..d9e5f33c5985f 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -430,8 +430,7 @@ public class Test { public ref struct S1{} }"; - // PROTOTYPE(verification) - CompileAndVerify(code, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs index ed3f29ad10985..63f45c384e29c 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs @@ -255,8 +255,7 @@ public class Test public void M() where T : unmanaged { } } "; - // PROTOTYPE(verification) - CompileAndVerify(text, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); @@ -281,8 +280,7 @@ public class Test where T : unmanaged { } "; - // PROTOTYPE(verification) - CompileAndVerify(text, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test`1").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs index 3660e696292af..65a8d04023049 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs @@ -1152,9 +1152,7 @@ public class Test { public void M(in int x) { } }"; - - // PROTOTYPE(verification) - CompileAndVerify(code, verify: Verification.FailsPeVerify | Verification.PassesIlVerify, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { AssertNoIsReadOnlyAttributeExists(module.ContainingAssembly); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs index fd8f0c697a7a7..ac62d8a61f384 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs @@ -215,10 +215,10 @@ class Structs }; CompileAndVerify(verifiable, assemblyValidator: validator); - CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.ClassLayout); + CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.FailsPeVerify_ClassLayout); // CLR limitation on type size, not a RefEmit bug: - CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.ClassLayout); + CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.FailsPeVerify_ClassLayout); } [Fact] @@ -336,7 +336,7 @@ public class C : B } "; // type C can't be loaded - CompileAndVerify(source, verify: Verification.TypeLoadFailed); + CompileAndVerify(source, verify: Verification.FailsPeVerify_TypeLoadFailed); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index d063340df2227..64402ca94450e 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -954,8 +954,7 @@ public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(Ou } else { - // PROTOTYPE(verification) - CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Skipped, symbolValidator: module => + CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.FailsPeVerify_MissingManifest : Verification.Passes, symbolValidator: module => { var assemblyAttributes = module.ContainingAssembly.GetAttributes(); Assert.Equal(0, assemblyAttributes.Length); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs index 7f6ac7363ac80..886d687717292 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs @@ -3606,7 +3606,7 @@ public static int Main () // the resulting code does not need to verify // This is consistent with Dev10 behavior - CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.UnableToResolveToken, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); + CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.FailsPeVerify_UnableToResolveToken, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); } [Fact, WorkItem(544507, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544507")] @@ -5553,7 +5553,7 @@ public static void Main() {} // Dev10 Runtime Exception: // Unhandled Exception: System.TypeLoadException: Windows Runtime types can only be declared in Windows Runtime assemblies. - var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed, targetFramework: TargetFramework.Mscorlib40); + var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify_TypeLoadFailed, targetFramework: TargetFramework.Mscorlib40); } #endregion diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index 1a7706cd076f8..a27d7b95e201d 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2727,7 +2727,7 @@ static void Main() CompileAndVerify(ca); var cb = CreateCompilation(sourceB, options: TestOptions.ReleaseExe, assemblyName: "X", references: new[] { new CSharpCompilationReference(ca) }, parseOptions: parseOptions); - CompileAndVerify(cb, expectedOutput: "42", verify: Verification.IVT).Diagnostics.Verify(); + CompileAndVerify(cb, expectedOutput: "42", verify: Verification.FailsIlVerify_IVT).Diagnostics.Verify(); } [WorkItem(1095618, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095618")] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs index 20ab33be32aa1..cfc820bb5e91b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs @@ -1841,7 +1841,7 @@ public static void Main() hello 2 "; - CompileAndVerify(source, expectedOutput: expected, verify: Verification.LeaveIntoTry); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.FailsIlVerify_LeaveIntoTry); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs index bbdb1bd44399c..987ce2e106722 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs @@ -2479,7 +2479,7 @@ public static void Main() 2 0 "; - CompileAndVerify(source, expectedOutput: expected, verify: Verification.RuntimeArgumentHandle); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.FailsIlVerify_RuntimeArgumentHandle); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs index 93582bbba0afb..14462bede5c13 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs @@ -3117,9 +3117,10 @@ public static void Main() } }"; + // PEVerify: [ : Test::Main][mdToken=0x6000001][offset 0x00000009][found Native Int][expected unmanaged pointer] Unexpected type on the stack. var c = CompileAndVerifyUtil(text, options: TestOptions.UnsafeReleaseDll, - verify: Verification.FailsPeVerify | Verification.PassesIlVerify); // PROTOTYPE(verification) + verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); c.VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs index d15b3dc8b6926..f223188ffba46 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs @@ -1034,7 +1034,7 @@ public static void Main() } } "; - base.CompileAndVerify(source, verify: Verification.TypedReference, expectedOutput: "12"). + base.CompileAndVerify(source, verify: Verification.FailsIlVerify_TypedReference, expectedOutput: "12"). VerifyIL("Test.Main", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs index 4af422055c08d..5ff734413e842 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs @@ -2387,7 +2387,7 @@ public System.Collections.IEnumerable SomeNumbers() }"; // The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available. var compilation = CreateEmptyCompilation(new[] { Parse(source), Parse(corlib) }); - var verifier = CompileAndVerify(compilation, verify: Verification.TypeLoadFailed); + var verifier = CompileAndVerify(compilation, verify: Verification.FailsPeVerify_TypeLoadFailed); verifier.VerifyDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1)); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs index 700a895808ba7..de7b71053e168 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs @@ -745,8 +745,11 @@ void Main() // it is entirely possible that Enum.GetHashCode and int.GetHashCode // have different implementations - // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException + TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, 699fa24e-4ae5-4965-b7a7-166da051a9a9, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - CompileAndVerify(comp, verify: Verification.FailsPeVerify). + // PEVerify: + // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS (_VALUETYPE) in signature is a ValueType (Class,respectively). + // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS(_VALUETYPE) in signature is a ValueType (Class, respectively). + // Type load failed. + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). VerifyIL("program.Main()", @" { @@ -873,8 +876,8 @@ void Main() // but see the bug see VSW #396011, JIT needs references when loading // fields of certain clr-ambiguous structs (only possible when building mscorlib) - // PROTOTYPE(verification) Internal.TypeSystem.TypeSystemException+TypeLoadException : [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.String, cb9df1f8-9e67-4084-a523-059b000cf4b6, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - CompileAndVerify(comp, verify: Verification.FailsPeVerify). + // PEVerify: Type load failed. + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). VerifyIL("System.IntPtr..ctor(int)", @" { // Code size 10 (0xa) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs index 48c64199b7818..caa9dec8fb321 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs @@ -554,7 +554,7 @@ public void SubmissionEntryPoint() "s0.dll", SyntaxFactory.ParseSyntaxTree(source0, options: TestOptions.Script), references); - var verifier = CompileAndVerify(s0, verify: Verification.BadName); + var verifier = CompileAndVerify(s0, verify: Verification.FailsPeVerify_BadName); var methodData = verifier.TestData.GetMethodData(""); Assert.Equal("System.Threading.Tasks.Task", ((MethodSymbol)methodData.Method).ReturnType.ToDisplayString()); methodData.VerifyIL( diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs index fa0d6e65ded47..b7095e679539c 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs @@ -5233,8 +5233,7 @@ public RefLike M() public ref struct RefLike{} } "; - // PROTOTYPE(verification) Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var verifier = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- + var verifier = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- M --- ---"); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index fb6027f15f994..fe9521107b895 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -259,8 +259,7 @@ static void Main(string[] args) } } "; - // PROTOTYPE(verification) Unexpected type on the stack. - var compilation = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, expectedOutput: @""); + var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: @""); compilation.VerifyIL("S1.Equals(object)", @" @@ -449,8 +448,7 @@ static void Main() } } "; - // PROTOTYPE(verification) Unexpected type on the stack. - var compilation = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, expectedOutput: @" + var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: @" Abc 255 q"); @@ -1283,7 +1281,7 @@ public static void Main() } "; - var compilation = CompileAndVerify(source, expectedOutput: "11", verify: Verification.InvalidProgramVararg); + var compilation = CompileAndVerify(source, expectedOutput: "11", verify: Verification.FailsIlVerify_InvalidProgramVararg); compilation.VerifyIL("D.Main", @" @@ -2367,8 +2365,7 @@ static void Main(string[] args) } "; - // PROTOTYPE(verification) Unexpected type on the stack. - var compilation = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, expectedOutput: "0"); + var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: "0"); compilation.VerifyIL("Program.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 96f443f723275..87d8fd6003049 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -77,8 +77,7 @@ static void Main(object[] args) Console.WriteLine((((DoubleAndStruct)args[0]).y).x); } }"; - // PROTOTYPE(verification) Unexpected type on the stack. - var result = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, options: TestOptions.DebugDll); + var result = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -165,8 +164,7 @@ static void Main(object[] args) Console.WriteLine(((((OuterStruct)args[0]).z).y).x); } }"; - // PROTOTYPE(verification) Unexpected type on the stack. - var result = CompileAndVerify(source, verify: Verification.PassesPeVerify | Verification.FailsIlVerify, options: TestOptions.DebugDll); + var result = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -4361,7 +4359,7 @@ public static void M() Callee3(default(T), default(T)); } } -", verify: Verification.TypeDevNotNil, options: TestOptions.ReleaseExe); +", verify: Verification.FailsPeVerify_TypeDevNotNil, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 297 (0x129) @@ -4494,7 +4492,7 @@ public static void M() Callee3(); } } -", verify: Verification.TypeDevNotNil, options: TestOptions.ReleaseExe); +", verify: Verification.FailsPeVerify_TypeDevNotNil, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 34 (0x22) @@ -5261,7 +5259,7 @@ static void Test(in T r) } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.UnexpectedTypeOnStack); + var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); var expectedIL = @" { @@ -5282,7 +5280,7 @@ .maxstack 2 compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); // expect the same IL in the compat case since direct references are required and must be emitted with "readonly.", even though unverifiable - compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.UnexpectedTypeOnStack, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); + compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); } @@ -10460,7 +10458,7 @@ static void Main() Diagnostic(ErrorCode.WRN_ExternMethodNoImplementation, "Goo").WithArguments("Test.Goo()")); // NOTE: the resulting IL is unverifiable, but not an error for compat reasons - CompileAndVerify(comp, verify: Verification.TypeLoadFailed).VerifyIL("Test.Main", + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed).VerifyIL("Test.Main", @" { // Code size 11 (0xb) @@ -13329,7 +13327,7 @@ private void PrintArgList(ArgIterator args) "; var compilation = CompileAndVerify( source, - verify: Verification.InvalidProgramVararg, + verify: Verification.FailsIlVerify_InvalidProgramVararg, expectedOutput: @"Inside - TestVarArgs::ctor (__arglist) Inside - TestVarArgs::ctor (__arglist) System.Int32 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs index ec68d719468fe..b4eeffdd5b405 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs @@ -698,7 +698,7 @@ public class B : A Diagnostic(ErrorCode.WRN_FinalizeMethod, "Finalize")); // We produce unverifiable code here as per bug resolution (compat concerns, not common case). - CompileAndVerify(compilation, verify: Verification.TypeLoadFailed).VerifyIL("B.Finalize", + CompileAndVerify(compilation, verify: Verification.FailsPeVerify_TypeLoadFailed).VerifyIL("B.Finalize", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs index 2753bd1689581..7a2ae9e47797d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs @@ -4106,8 +4106,10 @@ static void Main() source: new[] { Parse(text) }, references: new[] { AacorlibRef }); - // PROTOTYPE(verification) - var verifier = CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.PassesIlVerify); + // PEVerify: + // Error: Assembly name contains leading spaces or path or extension. + // Type load failed. + var verifier = CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); verifier.VerifyIL("Program.Main", @" { // Code size 223 (0xdf) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index b54fd3a8eb70b..0fbd573cee9ad 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -10146,8 +10146,11 @@ No overflow from (S15*)0 + sizeof(S15) No overflow from (S15*)0 + sizeof(S16) No overflow from (S16*)0 + sizeof(S15)"; } - // PROTOTYPE(verification) - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify | Verification.PassesIlVerify); + // PEVerify: + // [ : C+<>c__DisplayClass0_0::
b__0][mdToken=0x6000005][offset 0x00000012][found Native Int][expected unmanaged pointer] Unexpected type on the stack. + // [ : C+<> c__DisplayClass0_0::< Main > b__1][mdToken= 0x6000006][offset 0x00000012][found Native Int][expected unmanaged pointer] Unexpected type on the stack. + // [ : C +<> c__DisplayClass0_0::< Main > b__2][mdToken = 0x6000007][offset 0x00000012][found Native Int][expected unmanaged pointer] Unexpected type on the stack. + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 3ed61ae892c9d..bed68a765afe7 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4724,7 +4724,7 @@ public void Bug769741() { var comp = CreateEmptyCompilation("", new[] { TestReferences.SymbolsTests.netModule.x64COFF }, options: TestOptions.DebugDll); // modules not supported in ref emit - CompileAndVerify(comp, verify: Verification.BadFormat); + CompileAndVerify(comp, verify: Verification.FailsPeVerify_BadFormat); Assert.NotSame(comp.Assembly.CorLibrary, comp.Assembly); comp.GetSpecialType(SpecialType.System_Int32); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs index 23060b6df71c0..1770dce00177f 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs @@ -5107,7 +5107,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); @@ -5166,7 +5166,7 @@ public async Task F() // older versions of mscorlib don't contain IteratorStateMachineAttribute Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5230,7 +5230,7 @@ public async Task F() Assert.NotNull(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5331,7 +5331,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs index f3d6b6791996c..d3b75f28b3638 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs @@ -206,7 +206,7 @@ public class Test : Class2 { } "; - CompileAndVerifyWithMscorlib40(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, verify: Verification.NotImplemented, assemblyValidator: (assembly) => + CompileAndVerifyWithMscorlib40(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, verify: Verification.FailsIlVerify_NotImplemented, assemblyValidator: (assembly) => { var refs2 = assembly.Modules[0].ReferencedAssemblies.Select(r => r.Name); Assert.Equal(2, refs2.Count()); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs index 9188df83143bf..176d66f653d68 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs @@ -1665,12 +1665,12 @@ .maxstack 2 } "; - var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.InvalidProgramVararg); + var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.FailsIlVerify_InvalidProgramVararg); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); - verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.InvalidProgramVararg); + verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.FailsIlVerify_InvalidProgramVararg); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); @@ -1779,9 +1779,9 @@ interface UsePia5 : ITest29 Assert.Equal(VarianceKind.None, t7.Variance); }; - CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed); + CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify_TypeLoadFailed); - CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed); + CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify_TypeLoadFailed); } [Fact] @@ -4708,11 +4708,11 @@ public void M1() var compilation3 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.TypeLoadFailed); + CompileAndVerify(compilation3, verify: Verification.FailsPeVerify_TypeLoadFailed); var compilation4 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.TypeLoadFailed); + CompileAndVerify(compilation4, verify: Verification.FailsPeVerify_TypeLoadFailed); } [Fact] @@ -5185,11 +5185,11 @@ public void M1() var compilation3 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.TypeLoadFailed); + CompileAndVerify(compilation3, verify: Verification.FailsPeVerify_TypeLoadFailed); var compilation4 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.TypeLoadFailed); + CompileAndVerify(compilation4, verify: Verification.FailsPeVerify_TypeLoadFailed); } [ConditionalFact(typeof(ClrOnly), Reason = ConditionalSkipReason.NoPiaNeedsDesktop)] @@ -5407,7 +5407,7 @@ static string MyEvent02Handler(string arg) { var app_compilation = CreateCompilation(App_cs, new[] { NetImpl_ref, IEvent_ref, CSharpRef }, options: TestOptions.ReleaseExe, assemblyName: "App"); - CompileAndVerify(app_compilation, verify: Verification.NoPia, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, + CompileAndVerify(app_compilation, verify: Verification.FailsIlVerify_NoPia, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, expectedOutput: @"E01 E02"); } diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index e2dbf4679f69f..b54918fa19ee1 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -26,6 +26,8 @@ namespace Microsoft.CodeAnalysis.Test.Utilities [Flags] public enum Verification { + // TODO2 simplify flags? Do we really need a Skipped? + // TODO2 tighten verification for cases below Skipped = 0, PassesPeVerify = 1 << 0, @@ -36,23 +38,25 @@ public enum Verification Passes = PassesPeVerify | PassesIlVerify, Fails = FailsPeVerify | FailsIlVerify, - IVT = PassesPeVerify | FailsIlVerify, // ILVerify is case-sensitive in IVT + FailsIlVerify_IVT = PassesPeVerify | FailsIlVerify, // ILVerify is case-sensitive in IVT + // TODO2 can we add FailsIlVerify here too and rename? FullNames = PassesPeVerify, // ILVerify uses simple names instead of full names - TypedReference = PassesPeVerify | FailsIlVerify, // ILVerify doesn't support TypedReference - InvalidProgramVararg = PassesPeVerify | FailsIlVerify, // ILVerify complains about InvalidProgramVararg - ClassLoadGeneral = PassesPeVerify | FailsIlVerify, // ILVerify complains about ClassLoadGeneral - NotImplemented = PassesPeVerify | FailsIlVerify, // ILVerify has some un-implemented cases in EcmaModule.GetType - NoPia = PassesPeVerify | FailsIlVerify, // ILVerify doesn't do NoPia unification - RuntimeArgumentHandle = PassesPeVerify | FailsIlVerify, // ILVerify reports: RuntimeArgumentHandle not supported in .NET Core - LeaveIntoTry = PassesPeVerify | FailsIlVerify, // ILVerify reports: Leave into try block. - - TypeLoadFailed = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain type load failed - UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: Unexpected type on the stack. - UnableToResolveToken = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about "unable to resolve token" - TypeDevNotNil = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. - ClassLayout = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. - BadName = FailsPeVerify | PassesIlVerify, // PEVerify complains about: Assembly name contains leading spaces or path or extension. - BadFormat = FailsPeVerify | PassesIlVerify, // PEVerify complains about: An attempt was made to load a program with an incorrect format. + FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify, // ILVerify doesn't support TypedReference + FailsIlVerify_InvalidProgramVararg = PassesPeVerify | FailsIlVerify, // ILVerify complains about InvalidProgramVararg + FailsIlVerify_ClassLoadGeneral = PassesPeVerify | FailsIlVerify, // ILVerify complains about ClassLoadGeneral + FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify, // ILVerify has some un-implemented cases in EcmaModule.GetType + FailsIlVerify_NoPia = PassesPeVerify | FailsIlVerify, // ILVerify doesn't do NoPia unification + FailsIlVerify_RuntimeArgumentHandle = PassesPeVerify | FailsIlVerify, // ILVerify reports: RuntimeArgumentHandle not supported in .NET Core + FailsIlVerify_LeaveIntoTry = PassesPeVerify | FailsIlVerify, // ILVerify reports: Leave into try block. + + FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain type load failed + FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: Unexpected type on the stack. + FailsPeVerify_UnableToResolveToken = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about "unable to resolve token" + FailsPeVerify_TypeDevNotNil = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. + FailsPeVerify_ClassLayout = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. + FailsPeVerify_BadName = FailsPeVerify | PassesIlVerify, // PEVerify complains about: Assembly name contains leading spaces or path or extension. + FailsPeVerify_BadFormat = FailsPeVerify | PassesIlVerify, // PEVerify complains about: An attempt was made to load a program with an incorrect format. + FailsPeVerify_MissingManifest = Verification.FailsPeVerify | Verification.PassesIlVerify, // PEVerify complains about: The module was expected to contain an assembly manifest. } /// From 7af8ecc03e4b94310be7f5e1211db4f4c7564f04 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 12:06:10 -0800 Subject: [PATCH 06/51] Tighten checks --- .../Attributes/AttributeTests_Assembly.cs | 1 + src/Compilers/Test/Core/CommonTestBase.cs | 28 +++++++++------ .../Desktop/DesktopRuntimeEnvironment.cs | 36 ++++++++++++++++++- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 7dc094dcb59f0..ee2b0e3597d92 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -298,6 +298,7 @@ public void MismatchedSurrogateInAssemblyCultureAttribute() string s = @"[assembly: System.Reflection.AssemblyCultureAttribute(""\uD800"")]"; var comp = CreateCompilation(s, options: TestOptions.ReleaseDll); + // TODO2 // PEVerify: // Warning: Invalid locale string. CompileAndVerify(comp, verify: Verification.Passes, symbolValidator: m => diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index b54918fa19ee1..4458dc04511d7 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -35,10 +35,18 @@ public enum Verification FailsPeVerify = 1 << 2, FailsIlVerify = 1 << 3, + TypeLoadFailed = 1 << 4, + UnexpectedTypeOnStack = 1 << 5, + UnableToResolveToken = 1 << 6, + TypeDevNotNil = 1 << 7, + ClassLayout = 1 << 8, + BadName = 1 << 9, + MissingManifest = 1 << 10, + Passes = PassesPeVerify | PassesIlVerify, Fails = FailsPeVerify | FailsIlVerify, - FailsIlVerify_IVT = PassesPeVerify | FailsIlVerify, // ILVerify is case-sensitive in IVT + FailsIlVerify_IVT = PassesPeVerify | FailsIlVerify, // ILVerify is case-sensitive in IVT // TODO2 can we add FailsIlVerify here too and rename? FullNames = PassesPeVerify, // ILVerify uses simple names instead of full names FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify, // ILVerify doesn't support TypedReference @@ -49,14 +57,14 @@ public enum Verification FailsIlVerify_RuntimeArgumentHandle = PassesPeVerify | FailsIlVerify, // ILVerify reports: RuntimeArgumentHandle not supported in .NET Core FailsIlVerify_LeaveIntoTry = PassesPeVerify | FailsIlVerify, // ILVerify reports: Leave into try block. - FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain type load failed - FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: Unexpected type on the stack. - FailsPeVerify_UnableToResolveToken = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about "unable to resolve token" - FailsPeVerify_TypeDevNotNil = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. - FailsPeVerify_ClassLayout = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. - FailsPeVerify_BadName = FailsPeVerify | PassesIlVerify, // PEVerify complains about: Assembly name contains leading spaces or path or extension. + FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify | TypeLoadFailed, // ILVerify doesn't complain type load failed + FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify | UnexpectedTypeOnStack, // ILVerify doesn't complain about: Unexpected type on the stack. + FailsPeVerify_UnableToResolveToken = FailsPeVerify | PassesIlVerify | UnableToResolveToken, // ILVerify doesn't complain about "unable to resolve token" + FailsPeVerify_TypeDevNotNil = FailsPeVerify | PassesIlVerify | TypeDevNotNil, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. + FailsPeVerify_ClassLayout = FailsPeVerify | PassesIlVerify | ClassLayout, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. + FailsPeVerify_BadName = FailsPeVerify | PassesIlVerify | BadName, // PEVerify complains about: Assembly name contains leading spaces or path or extension. FailsPeVerify_BadFormat = FailsPeVerify | PassesIlVerify, // PEVerify complains about: An attempt was made to load a program with an incorrect format. - FailsPeVerify_MissingManifest = Verification.FailsPeVerify | Verification.PassesIlVerify, // PEVerify complains about: The module was expected to contain an assembly manifest. + FailsPeVerify_MissingManifest = FailsPeVerify | PassesIlVerify | MissingManifest, // PEVerify complains about: The module was expected to contain an assembly manifest. } /// @@ -185,7 +193,7 @@ internal CompilationVerifier Emit( if (assemblyValidator != null || symbolValidator != null) { // We're dual-purposing emitters here. In this context, it - // tells the validator the version of Emit that is calling it. + // tells the validator the version of Emit that is calling it. RunValidators(verifier, assemblyValidator, symbolValidator); } @@ -647,7 +655,7 @@ private static void VerifyOperationTreeContracts(IOperation root) // all operations from spine should belong to the operation tree set VerifyOperationTreeSpine(semanticModel, set, child.Syntax); - // operation tree's node must be part of root of semantic model which is + // operation tree's node must be part of root of semantic model which is // owner of operation's lifetime Assert.True(semanticModel.Root.FullSpan.Contains(child.Syntax.FullSpan)); } diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index ff8b1f33eb89a..4c27274bf8442 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -392,8 +392,42 @@ public void Verify(Verification verification) { throw new Exception("Verification failed", ex); } + if ((verification & Verification.TypeLoadFailed) != 0 + && !ex.Message.Contains("Type load failed.")) + { + throw new Exception("Expected: Type load failed.", ex); + } + if ((verification & Verification.UnexpectedTypeOnStack) != 0 + && !ex.Message.Contains("Unexpected type on the stack.")) + { + throw new Exception("Expected: Unexpected type on the stack.", ex); + } + if ((verification & Verification.UnableToResolveToken) != 0 + && !ex.Message.Contains("Unable to resolve token.")) + { + throw new Exception("Expected: Unable to resolve token.", ex); + } + if ((verification & Verification.TypeDevNotNil) != 0 + && !ex.Message.Contains("which is not nil.")) + { + throw new Exception("Expected: [...] which is not nil.", ex); + } + if ((verification & Verification.ClassLayout) != 0 + && !ex.Message.Contains("marked AutoLayout.")) + { + throw new Exception("Expected: [...] marked AutoLayout.", ex); + } + if ((verification & Verification.BadName) != 0 + && !ex.Message.Contains("Assembly name contains leading spaces or path or extension.")) + { + throw new Exception("Expected: Assembly name contains leading spaces or path or extension.", ex); + } + if ((verification & Verification.MissingManifest) != 0 + && !ex.Message.Contains("was expected to contain an assembly manifest.")) + { + throw new Exception("Expected: was expected to contain an assembly manifest.", ex); + } } - } public string[] VerifyModules(string[] modulesToVerify) From 0ee5f6a635394a60a06fd8a08e5e5084ce78ed6d Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 13:29:33 -0800 Subject: [PATCH 07/51] Fix IL verification plumbing --- ...icrosoft.CodeAnalysis.Test.Utilities.csproj | 2 ++ .../Desktop/DesktopRuntimeEnvironment.cs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj index 25151e909aae4..7027dcf3bf103 100644 --- a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj +++ b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj @@ -105,6 +105,8 @@ + + diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index 4c27274bf8442..13bdc0e64723d 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -297,10 +297,10 @@ public IList GetAllModuleData() return GetEmitData().AllModuleData; } -#if NET461 +#if NET472 private class Resolver : ILVerify.ResolverBase { - private Dictionary> imagesByName = new Dictionary>(); + private readonly Dictionary> imagesByName = new Dictionary>(); internal Resolver(EmitData emitData) { @@ -309,16 +309,16 @@ internal Resolver(EmitData emitData) string name = module.SimpleName; var image = name == "mscorlib" - ? TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() + ? ImmutableArray.Empty // TODO2 TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() : module.Image; imagesByName.Add(name, image); } } - protected override PEReader ResolveCore(AssemblyName name) + protected override PEReader ResolveCore(string name) { - if (imagesByName.TryGetValue(name.Name, out var image)) + if (imagesByName.TryGetValue(name, out var image)) { return new PEReader(image); } @@ -337,7 +337,7 @@ public void Verify(Verification verification) var emitData = GetEmitData(); -#if NET461 +#if NET472 // IL Verify if ((verification & (Verification.PassesIlVerify | Verification.FailsIlVerify)) != 0) { @@ -352,16 +352,16 @@ public void Verify(Verification verification) // auto-detect which module is the "corlib" foreach (var module in emitData.AllModuleData) { - var name = new AssemblyName(module.SimpleName); + var name = module.SimpleName; var metadataReader = resolver.Resolve(name).GetMetadataReader(); if (metadataReader.AssemblyReferences.Count == 0) { - verifier.SetSystemModuleName(name); + verifier.SetSystemModuleName(new AssemblyName(name)); } } } - var result = verifier.Verify(resolver.Resolve(new AssemblyName(emitData.MainModule.FullName))); + var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); if (result.Count() > 0) { if ((verification & Verification.PassesIlVerify) != 0) From 1701dbb1c78931db925ccebb465c78aac718c44b Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 20:15:53 -0800 Subject: [PATCH 08/51] Transition ILVerify to Core test runner --- .../InternalsVisibleToAndStrongNameTests.cs | 3 +- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 71 +++++++++++++++++++ .../Desktop/DesktopRuntimeEnvironment.cs | 70 ------------------ 3 files changed, 73 insertions(+), 71 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index a27d7b95e201d..e1bb1c9b82be9 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2722,7 +2722,8 @@ static void Main() System.Console.Write(A.I); } }"; - + // TODO2 DesktopRuntimeEnvironment could not load ILVerification + // System.IO.FileLoadException : Could not load file or assembly 'ILVerification, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044) var ca = CreateCompilation(sourceA, options: TestOptions.ReleaseDll, assemblyName: "ClassLibrary2", parseOptions: parseOptions); CompileAndVerify(ca); diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index f8935f6337a90..c26b916d3f569 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -14,6 +14,10 @@ using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.Test.Utilities; using static Roslyn.Test.Utilities.RuntimeEnvironmentUtilities; +using System.Reflection.PortableExecutable; +using System.Reflection; +using System.Reflection.Metadata; +using Roslyn.Test.Utilities; namespace Roslyn.Test.Utilities.CoreClr { @@ -104,11 +108,78 @@ public int Execute(string moduleName, string[] args, string expectedOutput) public SortedSet GetMemberSignaturesFromMetadata(string fullyQualifiedTypeName, string memberName) => GetEmitData().GetMemberSignaturesFromMetadata(fullyQualifiedTypeName, memberName); + private class Resolver : ILVerify.ResolverBase + { + private readonly Dictionary> imagesByName = new Dictionary>(); + + internal Resolver(EmitData emitData) + { + foreach (var module in emitData.AllModuleData) + { + string name = module.SimpleName; + + var image = name == "mscorlib" + ? ImmutableArray.Empty // TODO2 TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() + : module.Image; + + imagesByName.Add(name, image); + } + } + + protected override PEReader ResolveCore(string name) + { + if (imagesByName.TryGetValue(name, out var image)) + { + return new PEReader(image); + } + + return null; + } + } + public void Verify(Verification verification) { var emitData = GetEmitData(); emitData.RuntimeData.PeverifyRequested = true; // TODO(https://github.com/dotnet/coreclr/issues/295): Implement peverify + + // TODO2 + // IL Verify + if ((verification & (Verification.PassesIlVerify | Verification.FailsIlVerify)) != 0) + { + var resolver = new Resolver(emitData); + var verifier = new ILVerify.Verifier(resolver); + if (emitData.AllModuleData.Any(m => m.SimpleName == "mscorlib")) + { + verifier.SetSystemModuleName(new AssemblyName("mscorlib")); + } + else + { + // auto-detect which module is the "corlib" + foreach (var module in emitData.AllModuleData) + { + var name = module.SimpleName; + var metadataReader = resolver.Resolve(name).GetMetadataReader(); + if (metadataReader.AssemblyReferences.Count == 0) + { + verifier.SetSystemModuleName(new AssemblyName(name)); + } + } + } + + var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); + if (result.Count() > 0) + { + if ((verification & Verification.PassesIlVerify) != 0) + { + throw new Exception("IL Verify failed: \r\n" + string.Join("\r\n", result.Select(r => r.Message))); + } + } + else if ((verification & Verification.FailsIlVerify) != 0) + { + throw new Exception("IL Verify succeeded unexpectedly"); + } + } } public string[] VerifyModules(string[] modulesToVerify) diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index 13bdc0e64723d..617da3c851ba9 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -297,37 +297,6 @@ public IList GetAllModuleData() return GetEmitData().AllModuleData; } -#if NET472 - private class Resolver : ILVerify.ResolverBase - { - private readonly Dictionary> imagesByName = new Dictionary>(); - - internal Resolver(EmitData emitData) - { - foreach (var module in emitData.AllModuleData) - { - string name = module.SimpleName; - - var image = name == "mscorlib" - ? ImmutableArray.Empty // TODO2 TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() - : module.Image; - - imagesByName.Add(name, image); - } - } - - protected override PEReader ResolveCore(string name) - { - if (imagesByName.TryGetValue(name, out var image)) - { - return new PEReader(image); - } - - return null; - } - } -#endif - public void Verify(Verification verification) { if (verification == Verification.Skipped) @@ -337,45 +306,6 @@ public void Verify(Verification verification) var emitData = GetEmitData(); -#if NET472 - // IL Verify - if ((verification & (Verification.PassesIlVerify | Verification.FailsIlVerify)) != 0) - { - var resolver = new Resolver(emitData); - var verifier = new ILVerify.Verifier(resolver); - if (emitData.AllModuleData.Any(m => m.SimpleName == "mscorlib")) - { - verifier.SetSystemModuleName(new AssemblyName("mscorlib")); - } - else - { - // auto-detect which module is the "corlib" - foreach (var module in emitData.AllModuleData) - { - var name = module.SimpleName; - var metadataReader = resolver.Resolve(name).GetMetadataReader(); - if (metadataReader.AssemblyReferences.Count == 0) - { - verifier.SetSystemModuleName(new AssemblyName(name)); - } - } - } - - var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); - if (result.Count() > 0) - { - if ((verification & Verification.PassesIlVerify) != 0) - { - throw new Exception("IL Verify failed: \r\n" + string.Join("\r\n", result.Select(r => r.Message))); - } - } - else if ((verification & Verification.FailsIlVerify) != 0) - { - throw new Exception("IL Verify succeeded unexpectedly"); - } - } -#endif - // PE Verify try { From 260a40e39d4e4f085f614e8f3a51c5e186f74b4d Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 20:34:00 -0800 Subject: [PATCH 09/51] Fix Resolver --- .../Platform/CoreClr/CoreCLRRuntimeEnvironment.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index c26b916d3f569..6dd79faf1c32f 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -116,13 +116,15 @@ internal Resolver(EmitData emitData) { foreach (var module in emitData.AllModuleData) { - string name = module.SimpleName; + string name = module.FullName; - var image = name == "mscorlib" - ? ImmutableArray.Empty // TODO2 TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() - : module.Image; + //var image = name == "mscorlib" + // ? ImmutableArray.Empty // TODO2 TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() + // : module.Image; + var image = module.Image; imagesByName.Add(name, image); + imagesByName.Add(module.SimpleName, image); } } @@ -149,9 +151,10 @@ public void Verify(Verification verification) { var resolver = new Resolver(emitData); var verifier = new ILVerify.Verifier(resolver); - if (emitData.AllModuleData.Any(m => m.SimpleName == "mscorlib")) + var mscorlibModules = emitData.AllModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); + if (mscorlibModules.Length == 1) { - verifier.SetSystemModuleName(new AssemblyName("mscorlib")); + verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); } else { From 7b0263ada88adb9b1b1e2a961f59318cf2bf8412 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 20:37:01 -0800 Subject: [PATCH 10/51] public --- .../CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs index 958e60b3e1db4..d7e3f74b4c547 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs @@ -7613,7 +7613,7 @@ static void Main() } [Fact] - void InvokeVarForLvalueInParens() + public void InvokeVarForLvalueInParens() { var source = @" class Program From 400d315a70747e9ac34f267150a732e7ac2ddf1b Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 20:57:34 -0800 Subject: [PATCH 11/51] Start tightening the IL verification --- .../InternalsVisibleToAndStrongNameTests.cs | 4 +--- .../Test/Emit/CodeGen/CodeGenStructsAndEnum.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 3 +-- .../CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs | 4 ++-- src/Compilers/Test/Core/CommonTestBase.cs | 12 +++++++----- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 16 ++++++++++++++-- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index e1bb1c9b82be9..b25ca9823064a 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2722,13 +2722,11 @@ static void Main() System.Console.Write(A.I); } }"; - // TODO2 DesktopRuntimeEnvironment could not load ILVerification - // System.IO.FileLoadException : Could not load file or assembly 'ILVerification, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044) var ca = CreateCompilation(sourceA, options: TestOptions.ReleaseDll, assemblyName: "ClassLibrary2", parseOptions: parseOptions); CompileAndVerify(ca); var cb = CreateCompilation(sourceB, options: TestOptions.ReleaseExe, assemblyName: "X", references: new[] { new CSharpCompilationReference(ca) }, parseOptions: parseOptions); - CompileAndVerify(cb, expectedOutput: "42", verify: Verification.FailsIlVerify_IVT).Diagnostics.Verify(); + CompileAndVerify(cb, expectedOutput: "42", verify: Verification.Passes).Diagnostics.Verify(); } [WorkItem(1095618, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095618")] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index fe9521107b895..231e5cefd5658 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -1281,7 +1281,7 @@ public static void Main() } "; - var compilation = CompileAndVerify(source, expectedOutput: "11", verify: Verification.FailsIlVerify_InvalidProgramVararg); + var compilation = CompileAndVerify(source, expectedOutput: "11", verify: Verification.Passes); compilation.VerifyIL("D.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 87d8fd6003049..1cc9b9976c6d4 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -13322,12 +13322,11 @@ private void PrintArgList(ArgIterator args) } } } - } "; var compilation = CompileAndVerify( source, - verify: Verification.FailsIlVerify_InvalidProgramVararg, + verify: Verification.Passes, expectedOutput: @"Inside - TestVarArgs::ctor (__arglist) Inside - TestVarArgs::ctor (__arglist) System.Int32 diff --git a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs index 176d66f653d68..96cf87933988b 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs @@ -1665,12 +1665,12 @@ .maxstack 2 } "; - var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.FailsIlVerify_InvalidProgramVararg); + var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.Passes); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); - verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.FailsIlVerify_InvalidProgramVararg); + verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.Passes); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index 4458dc04511d7..d7fe8fed815f7 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -35,6 +35,9 @@ public enum Verification FailsPeVerify = 1 << 2, FailsIlVerify = 1 << 3, + TypedReference = 1 << 12, + NotImplemented = 1 << 13, + TypeLoadFailed = 1 << 4, UnexpectedTypeOnStack = 1 << 5, UnableToResolveToken = 1 << 6, @@ -46,13 +49,12 @@ public enum Verification Passes = PassesPeVerify | PassesIlVerify, Fails = FailsPeVerify | FailsIlVerify, - FailsIlVerify_IVT = PassesPeVerify | FailsIlVerify, // ILVerify is case-sensitive in IVT // TODO2 can we add FailsIlVerify here too and rename? FullNames = PassesPeVerify, // ILVerify uses simple names instead of full names - FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify, // ILVerify doesn't support TypedReference - FailsIlVerify_InvalidProgramVararg = PassesPeVerify | FailsIlVerify, // ILVerify complains about InvalidProgramVararg - FailsIlVerify_ClassLoadGeneral = PassesPeVerify | FailsIlVerify, // ILVerify complains about ClassLoadGeneral - FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify, // ILVerify has some un-implemented cases in EcmaModule.GetType + FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify | TypedReference, // ILVerify doesn't support TypedReference + //FailsIlVerify_InvalidProgramVararg = PassesPeVerify | FailsIlVerify | InvalidProgramVararg, // ILVerify complains about InvalidProgramVararg + //FailsIlVerify_ClassLoadGeneral = PassesPeVerify | FailsIlVerify, // ILVerify complains about ClassLoadGeneral + FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify | NotImplemented, // ILVerify has some un-implemented cases in EcmaModule.GetType FailsIlVerify_NoPia = PassesPeVerify | FailsIlVerify, // ILVerify doesn't do NoPia unification FailsIlVerify_RuntimeArgumentHandle = PassesPeVerify | FailsIlVerify, // ILVerify reports: RuntimeArgumentHandle not supported in .NET Core FailsIlVerify_LeaveIntoTry = PassesPeVerify | FailsIlVerify, // ILVerify reports: Leave into try block. diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 6dd79faf1c32f..56cab59230e4c 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -123,8 +123,9 @@ internal Resolver(EmitData emitData) // : module.Image; var image = module.Image; + // TODO2 figure out why we need both the simple name and full name imagesByName.Add(name, image); - imagesByName.Add(module.SimpleName, image); + imagesByName.TryAdd(module.SimpleName, image); } } @@ -173,9 +174,20 @@ public void Verify(Verification verification) var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); if (result.Count() > 0) { + string message = string.Join("\r\n", result.Select(r => r.Message)); if ((verification & Verification.PassesIlVerify) != 0) { - throw new Exception("IL Verify failed: \r\n" + string.Join("\r\n", result.Select(r => r.Message))); + throw new Exception("IL Verify failed: \r\n" + message); + } + if ((verification & Verification.BadName) != 0 + && !message.Contains("TypedReference not supported in .NET Core")) + { + throw new Exception("Expected: TypedReference not supported in .NET Core"); + } + if ((verification & Verification.NotImplemented) != 0 + && !message.Contains("The method or operation is not implemented.")) + { + throw new Exception("Expected: The method or operation is not implemented."); } } else if ((verification & Verification.FailsIlVerify) != 0) From e7a7c3f8dbc2f6394a682b9d65e48cd992d55c63 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 30 Dec 2021 21:07:55 -0800 Subject: [PATCH 12/51] Remove some unused error entries --- .../CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs | 2 +- .../Emit/EditAndContinue/AssemblyReferencesTests.cs | 2 +- src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs | 2 +- src/Compilers/Test/Core/CommonTestBase.cs | 10 ++-------- .../Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs | 2 +- 6 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs index cfc820bb5e91b..a3d51f3d389e2 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs @@ -1841,7 +1841,7 @@ public static void Main() hello 2 "; - CompileAndVerify(source, expectedOutput: expected, verify: Verification.FailsIlVerify_LeaveIntoTry); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.Passes); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs index 987ce2e106722..f63f58685ac9d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs @@ -2479,7 +2479,7 @@ public static void Main() 2 0 "; - CompileAndVerify(source, expectedOutput: expected, verify: Verification.FailsIlVerify_RuntimeArgumentHandle); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.Passes); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs index 9e86e4510e789..efea9625ae66e 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs @@ -481,7 +481,7 @@ class C var compilation0 = CreateEmptyCompilation(src0, new[] { MscorlibRef, ref01, ref11 }, assemblyName: "C", options: TestOptions.DebugDll); var compilation1 = compilation0.WithSource(src1).WithReferences(new[] { MscorlibRef, ref02, ref12 }); - var v0 = CompileAndVerify(compilation0, verify: Verification.FullNames); + var v0 = CompileAndVerify(compilation0, verify: Verification.Passes); var f0 = compilation0.GetMember("C.F"); var f1 = compilation1.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs index 96cf87933988b..7c5cd97c611e4 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs @@ -5407,7 +5407,7 @@ static string MyEvent02Handler(string arg) { var app_compilation = CreateCompilation(App_cs, new[] { NetImpl_ref, IEvent_ref, CSharpRef }, options: TestOptions.ReleaseExe, assemblyName: "App"); - CompileAndVerify(app_compilation, verify: Verification.FailsIlVerify_NoPia, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, + CompileAndVerify(app_compilation, verify: Verification.Passes, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, expectedOutput: @"E01 E02"); } diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index d7fe8fed815f7..2a328113cbecc 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -27,7 +27,6 @@ namespace Microsoft.CodeAnalysis.Test.Utilities public enum Verification { // TODO2 simplify flags? Do we really need a Skipped? - // TODO2 tighten verification for cases below Skipped = 0, PassesPeVerify = 1 << 0, @@ -35,9 +34,11 @@ public enum Verification FailsPeVerify = 1 << 2, FailsIlVerify = 1 << 3, + // ILVerify errors TypedReference = 1 << 12, NotImplemented = 1 << 13, + // PEVerify errors TypeLoadFailed = 1 << 4, UnexpectedTypeOnStack = 1 << 5, UnableToResolveToken = 1 << 6, @@ -49,15 +50,8 @@ public enum Verification Passes = PassesPeVerify | PassesIlVerify, Fails = FailsPeVerify | FailsIlVerify, - // TODO2 can we add FailsIlVerify here too and rename? - FullNames = PassesPeVerify, // ILVerify uses simple names instead of full names FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify | TypedReference, // ILVerify doesn't support TypedReference - //FailsIlVerify_InvalidProgramVararg = PassesPeVerify | FailsIlVerify | InvalidProgramVararg, // ILVerify complains about InvalidProgramVararg - //FailsIlVerify_ClassLoadGeneral = PassesPeVerify | FailsIlVerify, // ILVerify complains about ClassLoadGeneral FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify | NotImplemented, // ILVerify has some un-implemented cases in EcmaModule.GetType - FailsIlVerify_NoPia = PassesPeVerify | FailsIlVerify, // ILVerify doesn't do NoPia unification - FailsIlVerify_RuntimeArgumentHandle = PassesPeVerify | FailsIlVerify, // ILVerify reports: RuntimeArgumentHandle not supported in .NET Core - FailsIlVerify_LeaveIntoTry = PassesPeVerify | FailsIlVerify, // ILVerify reports: Leave into try block. FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify | TypeLoadFailed, // ILVerify doesn't complain type load failed FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify | UnexpectedTypeOnStack, // ILVerify doesn't complain about: Unexpected type on the stack. diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 56cab59230e4c..1d2836b344409 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -179,7 +179,7 @@ public void Verify(Verification verification) { throw new Exception("IL Verify failed: \r\n" + message); } - if ((verification & Verification.BadName) != 0 + if ((verification & Verification.TypedReference) != 0 && !message.Contains("TypedReference not supported in .NET Core")) { throw new Exception("Expected: TypedReference not supported in .NET Core"); From 9cafb537de40e4fccd5962dbdb6cc5d7254d6610 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Fri, 31 Dec 2021 00:18:30 -0800 Subject: [PATCH 13/51] Annotate failures --- .../Emit/Attributes/AttributeTests_Assembly.cs | 1 + .../Emit/Attributes/AttributeTests_Dynamic.cs | 4 +++- .../Emit/Attributes/AttributeTests_IsByRefLike.cs | 1 + .../Emit/Attributes/AttributeTests_IsUnmanaged.cs | 5 +++++ .../Attributes/AttributeTests_ReadOnlyStruct.cs | 1 + .../Emit/Attributes/AttributeTests_RefReadOnly.cs | 1 + .../Emit/Attributes/AttributeTests_Synthesized.cs | 1 + .../AttributeTests_WellKnownAttributes.cs | 3 ++- .../InternalsVisibleToAndStrongNameTests.cs | 1 + .../Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs | 1 + .../Test/Emit/CodeGen/CodeGenForEachTests.cs | 9 +++++++++ .../CSharp/Test/Emit/CodeGen/CodeGenIterators.cs | 1 + .../CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs | 2 ++ .../CodeGen/CodeGenShortCircuitOperatorTests.cs | 1 + .../CodeGen/CodeGenStackAllocInitializerTests.cs | 3 ++- .../Test/Emit/CodeGen/CodeGenStructsAndEnum.cs | 3 +++ .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 5 ++++- .../CSharp/Test/Emit/CodeGen/UnsafeTests.cs | 15 +++++++++------ .../CSharp/Test/Emit/Emit/CompilationEmitTests.cs | 3 +++ .../CSharp/Test/Emit/Emit/EmitCustomModifiers.cs | 4 ++-- .../CSharp/Test/Emit/Emit/EmitErrorTests.cs | 3 +++ .../CSharp/Test/Emit/Emit/EmitMetadataTests.cs | 2 ++ 22 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index ee2b0e3597d92..6368a1d45a53b 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -544,6 +544,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); + // TODO2 ILVerify: Assembly or module not found: hash_module CompileAndVerify(compilation, verify: Verification.Passes, manifestResources: hash_resources, diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index 9e4cdde32da7e..e06e8b7749f40 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1156,7 +1156,8 @@ static void Main() comp.VerifyDiagnostics(); // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); + // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); } [Fact] @@ -1191,6 +1192,7 @@ static void Main() comp.VerifyDiagnostics(); // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. + // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); } diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index d9e5f33c5985f..522355161fe77 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -430,6 +430,7 @@ public class Test { public ref struct S1{} }"; + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs index 63f45c384e29c..107d4301b79f4 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs @@ -255,6 +255,8 @@ public class Test public void M() where T : unmanaged { } } "; + // TODO2 AssemblyTable.NumberOfRows on the MetadataReader is 0 (so IsAssembly is false) + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").TypeParameters.Single(); @@ -280,6 +282,7 @@ public class Test where T : unmanaged { } "; + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test`1").TypeParameters.Single(); @@ -312,6 +315,7 @@ void N() where T : unmanaged } "; + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify( source: text, verify: Verification.Fails, @@ -341,6 +345,7 @@ public class IsUnmanagedAttribute : System.Attribute { } public delegate void D() where T : unmanaged; "; + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify( source: text, verify: Verification.Fails, diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs index 159326acfd8e6..98818228ca92b 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs @@ -427,6 +427,7 @@ public class Test public readonly struct S1{} }"; + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs index 65a8d04023049..7a8cfd717a0ff 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs @@ -1152,6 +1152,7 @@ public class Test { public void M(in int x) { } }"; + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { AssertNoIsReadOnlyAttributeExists(module.ContainingAssembly); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index 64402ca94450e..d9dccd29ba966 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -954,6 +954,7 @@ public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(Ou } else { + // TODO2 Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.FailsPeVerify_MissingManifest : Verification.Passes, symbolValidator: module => { var assemblyAttributes = module.ContainingAssembly.GetAttributes(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs index 886d687717292..08a5a780a25a8 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs @@ -12564,7 +12564,8 @@ void M() } "; - var comp = CompileAndVerify(source, options: TestOptions.DebugModule.WithAllowUnsafe(true), verify: Verification.Fails); + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid + var comp = CompileAndVerify(source, options: TestOptions.DebugModule.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_MissingManifest); Assert.False(comp.HasLocalsInit("C.M")); } diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index b25ca9823064a..04c74c6f3972f 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2671,6 +2671,7 @@ public A GetA() references: new[] { new CSharpCompilationReference(ca) }, parseOptions: parseOptions); + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify(cb, verify: Verification.Fails).Diagnostics.Verify(); } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs index baf85196a56ef..250412f72658a 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs @@ -6161,6 +6161,7 @@ public static async IAsyncEnumerator GetAsyncEnumerator(this Range range) options: TestOptions.DebugExe, parseOptions: TestOptions.Regular9); comp.VerifyDiagnostics(); + // TODO2 Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "123"); } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs index 4ebd2028fb9b0..30c5d89bf344d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs @@ -1384,6 +1384,7 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose() { System.Console.WriteLine(""Done with DisposableEnumerator""); } }"; + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var compilation = CompileAndVerify(source, expectedOutput: @" 1 2 @@ -1447,6 +1448,7 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose(params object[] args) { System.Console.WriteLine($""Done with DisposableEnumerator. args was {args}, length {args.Length}""); } }"; + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var compilation = CompileAndVerify(source, expectedOutput: @" 1 2 @@ -1481,6 +1483,7 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose(int arg = 1) { System.Console.WriteLine($""Done with DisposableEnumerator. arg was {arg}""); } }"; + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var compilation = CompileAndVerify(source, expectedOutput: @" 1 2 @@ -1521,6 +1524,7 @@ static class DisposeExtension } "; // extension methods do not contribute to disposal + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. CompileAndVerify(source, expectedOutput: @"123"); } @@ -1561,6 +1565,7 @@ static class DisposeExtension2 } "; // extension methods do not contribute to disposal + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. CompileAndVerify(source, expectedOutput: @"123"); } @@ -1597,6 +1602,7 @@ static class DisposeExtension } "; // extension methods do not contribute to disposal + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. CompileAndVerify(source, expectedOutput: @"123"); } @@ -1633,6 +1639,7 @@ static class DisposeExtension } "; // extension methods do not contribute to disposal + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. CompileAndVerify(source, expectedOutput: @"123"); } @@ -1729,6 +1736,7 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose() { System.Console.WriteLine(""Done with DisposableEnumerator""); } }"; + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var compilation = CompileAndVerify(source, parseOptions: TestOptions.Regular7_3, expectedOutput: @" 1 2 @@ -4725,6 +4733,7 @@ ref struct Enumerator public bool MoveNext() => Current++ != 3; public void Dispose() { Console.Write(""Disposed""); } }"; + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. CompileAndVerify(source, parseOptions: TestOptions.Regular9, expectedOutput: @"123Disposed") .VerifyIL("C.Main", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs index 5ff734413e842..15b0342d4aa80 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs @@ -2387,6 +2387,7 @@ public System.Collections.IEnumerable SomeNumbers() }"; // The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available. var compilation = CreateEmptyCompilation(new[] { Parse(source), Parse(corlib) }); + // TODO2 ILVerify: Return from .ctor when this is uninitialized. Unexpected type on the stack. var verifier = CompileAndVerify(compilation, verify: Verification.FailsPeVerify_TypeLoadFailed); verifier.VerifyDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs index de7b71053e168..dfbcc3116b3c2 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs @@ -749,6 +749,7 @@ void Main() // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS (_VALUETYPE) in signature is a ValueType (Class,respectively). // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS(_VALUETYPE) in signature is a ValueType (Class, respectively). // Type load failed. + // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). VerifyIL("program.Main()", @" @@ -877,6 +878,7 @@ void Main() // fields of certain clr-ambiguous structs (only possible when building mscorlib) // PEVerify: Type load failed. + // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). VerifyIL("System.IntPtr..ctor(int)", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs index b7095e679539c..7071fa514608b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs @@ -5233,6 +5233,7 @@ public RefLike M() public ref struct RefLike{} } "; + // TODO: ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var verifier = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- M --- diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs index 418c3a0778b2b..b539119f504a5 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs @@ -488,10 +488,11 @@ static void Main() } } "; + // PEVerify: [ : C::Main][mdToken=0x6000002][offset 0x00000002][found Native Int][expected unmanaged pointer] Unexpected type on the stack. CompileAndVerify(text, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_3), options: TestOptions.UnsafeReleaseExe, - verify: Verification.Fails).VerifyIL("C.Main", + verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.Main", @"{ // Code size 8 (0x8) .maxstack 1 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index 231e5cefd5658..fb027ea432f33 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -259,6 +259,7 @@ static void Main(string[] args) } } "; + // TODO2 ILVerify: Unexpected type on the stack. var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: @""); compilation.VerifyIL("S1.Equals(object)", @@ -448,6 +449,7 @@ static void Main() } } "; + // TODO2 ILVerify: Unexpected type on the stack. var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: @" Abc 255 @@ -2365,6 +2367,7 @@ static void Main(string[] args) } "; + // TODO2 ILVerify: Unexpected type on the stack. var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: "0"); compilation.VerifyIL("Program.Main", diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 1cc9b9976c6d4..320cdca25fc41 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -77,6 +77,7 @@ static void Main(object[] args) Console.WriteLine((((DoubleAndStruct)args[0]).y).x); } }"; + // TODO2 ILVerify: Unexpected type on the stack. var result = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @@ -164,6 +165,7 @@ static void Main(object[] args) Console.WriteLine(((((OuterStruct)args[0]).z).y).x); } }"; + // TODO2 ILVerify: Unexpected type on the stack. var result = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @@ -5259,6 +5261,7 @@ static void Test(in T r) } }"; + // TODO2 ILVerify: Unexpected type on the stack. var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); var expectedIL = @" @@ -17216,7 +17219,7 @@ static async Task MethodAsync() System.Threading.Tasks.Task`1[System.Object] Success True -").VerifyDiagnostics(); +", verify: Verification.FailsIlVerify_TypedReference).VerifyDiagnostics(); } } } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index 0fbd573cee9ad..01fd8daa5c9af 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -5812,7 +5812,7 @@ void M(int* pi, void* pv, sbyte sb, byte b, short s, ushort us, int i, uint ui, } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyIL("C.M", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.M", @" { // Code size 79 (0x4f) .maxstack 1 @@ -5902,7 +5902,7 @@ void M(int* pi, void* pv, sbyte sb, byte b, short s, ushort us, int i, uint ui, } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyIL("C.M", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.M", @" { // Code size 79 (0x4f) .maxstack 1 @@ -6499,7 +6499,7 @@ static void Main() } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "1234", verify: Verification.Fails).VerifyIL("C.Main", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "1234", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.Main", @" { // Code size 120 (0x78) .maxstack 5 @@ -9784,7 +9784,7 @@ public static implicit operator C(int* p) } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyIL("C.M", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.M", @" { // Code size 12 (0xc) .maxstack 1 @@ -10854,7 +10854,7 @@ unsafe struct S1 "; - var verifier = CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll.WithConcurrentBuild(false), verify: Verification.Fails); + var verifier = CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll.WithConcurrentBuild(false), verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); } [Fact, WorkItem(748530, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/748530")] @@ -11370,7 +11370,10 @@ public static unsafe int Test(params int*[] types) return types.Length; } }"; - var comp = CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: "0", verify: Verification.Fails); + // PEVerify: + // [ : Program::Main][mdToken= 0x6000001][offset 0x00000001] Unmanaged pointers are not a verifiable type. + // [ : Program::Main][mdToken = 0x6000001][offset 0x00000001] Unable to resolve token. + var comp = CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: "0", verify: Verification.FailsPeVerify_UnableToResolveToken); comp.VerifyIL("Program.Main", @" { // Code size 17 (0x11) diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index bed68a765afe7..634475e666b25 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4309,6 +4309,7 @@ public void EmitNetModuleWithReferencedNetModule() string source2 = @"public class B: A {}"; var comp = CreateCompilation(source1, options: TestOptions.ReleaseModule); var metadataRef = ModuleMetadata.CreateFromStream(comp.EmitToStream()).GetReference(); + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify(source2, references: new[] { metadataRef }, options: TestOptions.ReleaseModule, verify: Verification.Fails); } @@ -4724,6 +4725,7 @@ public void Bug769741() { var comp = CreateEmptyCompilation("", new[] { TestReferences.SymbolsTests.netModule.x64COFF }, options: TestOptions.DebugDll); // modules not supported in ref emit + // TODO2 ILVerify: Internal.IL.VerifierException : No system module specified CompileAndVerify(comp, verify: Verification.FailsPeVerify_BadFormat); Assert.NotSame(comp.Assembly.CorLibrary, comp.Assembly); comp.GetSpecialType(SpecialType.System_Int32); @@ -5229,6 +5231,7 @@ public void CompileAndVerifyModuleIncludesAllModules() var modRef = CreateCompilation("public class A { }", options: TestOptions.ReleaseModule, assemblyName: "refMod").EmitToImageReference(); var comp = CreateCompilation("public class B : A { }", references: new[] { modRef }, assemblyName: "sourceMod"); + // TODO2 ILVerify: Assembly or module not found: refMod CompileAndVerify(comp, symbolValidator: module => { var b = module.GlobalNamespace.GetTypeMember("B"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs index 57b74980239f0..6826b90ec8674 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs @@ -705,7 +705,7 @@ static void Main() }"; var compilation = CreateCompilationWithILAndMscorlib40(source, ilSource, options: TestOptions.UnsafeReleaseExe); compilation.VerifyDiagnostics(); - CompileAndVerify(compilation, verify: Verification.Fails); + CompileAndVerify(compilation, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); } [Fact] @@ -739,7 +739,7 @@ static void Main() }"; var compilation = CreateCompilationWithILAndMscorlib40(source, ilSource, options: TestOptions.UnsafeReleaseExe); compilation.VerifyDiagnostics(); - CompileAndVerify(compilation, verify: Verification.Fails); + CompileAndVerify(compilation, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); } } } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs index 3a559fcdc2531..37feb83a8de0e 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs @@ -110,6 +110,7 @@ public static void Main() } } "; + // TODO2 ILVerify null ref var compilation2 = CompileAndVerify( source2, new[] { new CSharpCompilationReference(compilation1) }, @@ -142,6 +143,7 @@ public static void Main() } } "; + // TODO2 ILVerify null ref var compilation2 = CompileAndVerify( source2, new[] { new CSharpCompilationReference(compilation1) }, @@ -179,6 +181,7 @@ public static void Main() } "; + // TODO2 ILVerify null ref var compilation2 = CompileAndVerify( source2, new[] { new CSharpCompilationReference(compilation1) }, diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs index d3b75f28b3638..a46dc405b9ae9 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs @@ -224,6 +224,7 @@ public class Test : Class2 [Fact()] public void Bug687434() { + // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify( "public class C { }", verify: Verification.Fails, @@ -242,6 +243,7 @@ public class Test : Class1 } "; // modules not supported in ref emit + // TODO2 ILVerify: Assembly or module not found: netModule1 CompileAndVerify(source, new[] { netModule1, netModule2 }, assemblyValidator: (assembly) => { Assert.Equal(3, assembly.Modules.Length); From 656d328e03aacc9ba2d9521ebcec688b626c0bae Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 10:25:51 -0800 Subject: [PATCH 14/51] InitOnly and NotVisible --- .../Test/Semantic/Semantics/ArglistTests.cs | 11 ++-- .../Semantic/Semantics/BetterCandidates.cs | 1 + .../BindingAsyncTasklikeMoreTests.cs | 1 + .../Semantic/Semantics/DelegateTypeTests.cs | 4 ++ .../Test/Semantic/Semantics/DynamicTests.cs | 2 + .../Test/Semantic/Semantics/ForEachTests.cs | 1 + .../Semantics/FunctionPointerTests.cs | 1 + .../Semantic/Semantics/InitOnlyMemberTests.cs | 18 +++---- .../Semantic/Semantics/InterpolationTests.cs | 2 + .../Semantics/NamedAndOptionalTests.cs | 1 + .../Semantics/NullableReferenceTypesTests.cs | 1 + .../Semantics/OverloadResolutionTests.cs | 2 + .../Semantics/PatternMatchingTests.cs | 3 +- .../Semantics/PatternMatchingTests3.cs | 1 + .../PatternMatchingTests_ListPatterns.cs | 20 ++++++++ .../Semantics/TargetTypedDefaultTests.cs | 2 +- .../Symbol/Compilation/CompilationAPITests.cs | 1 + .../DefaultInterfaceImplementationTests.cs | 50 +++++++++++-------- .../Test/Symbol/Symbols/SymbolErrorTests.cs | 1 + src/Compilers/Test/Core/CommonTestBase.cs | 7 +++ .../CoreClr/CoreCLRRuntimeEnvironment.cs | 10 ++++ .../Desktop/DesktopRuntimeEnvironment.cs | 6 +++ .../Test/Utilities/CSharp/CSharpTestBase.cs | 1 + 23 files changed, 110 insertions(+), 37 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs index 7b23e2a17ae05..f0d2fbc5d588c 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; +using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; @@ -189,7 +190,7 @@ .locals init (int V_0) //i IL_0013: ret }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "System.Int32"); + var verifier = CompileAndVerify(source: text, expectedOutput: "System.Int32", verify: Verification.FailsIlVerify_TypedReference); verifier.VerifyIL("C.Main", expectedIL); } @@ -357,7 +358,7 @@ .maxstack 1 IL_0008: ret }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "System.String"); + var verifier = CompileAndVerify(source: text, expectedOutput: "System.String", verify: Verification.FailsIlVerify_TypedReference); verifier.VerifyIL("C.M", expectedIL); } @@ -672,7 +673,7 @@ .maxstack 2 IL_000c: ret }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "1123"); + var verifier = CompileAndVerify(source: text, expectedOutput: "1123", verify: Verification.FailsIlVerify_TypedReference); verifier.VerifyIL("C.Get", expectedGetIL); verifier.VerifyIL("C.Set", expectedSetIL); verifier.VerifyIL("C.Ref", expectedRefIL); @@ -794,7 +795,7 @@ .locals init (int V_0, //x 42 333 0 -42"); +42", verify: Verification.FailsIlVerify_TypedReference); verifier.VerifyIL("Program.Main", expectedGetIL); } @@ -902,7 +903,7 @@ static void Main() } }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "4242"); + var verifier = CompileAndVerify(source: text, expectedOutput: "4242", verify: Verification.FailsIlVerify_TypedReference); verifier.VerifyIL("C.Main", @" { // Code size 72 (0x48) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs index 32280b50301e3..d0594ce3bf86a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs @@ -862,6 +862,7 @@ public class ExtensionAttribute : System.Attribute {} ); var compilation = CreateCompilationWithBetterCandidates(source, options: TestOptions.ReleaseExe).VerifyDiagnostics( ); + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. CompileAndVerify(compilation, expectedOutput: "2"); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs index fbf712806045b..a0493340e1057 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs @@ -1587,6 +1587,7 @@ public static void M(MyResult r) var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); compilation.VerifyDiagnostics(); + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. CompileAndVerify(compilation, expectedOutput: "3"); compilation = CreateCompilation(source, options: TestOptions.DebugExe); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs index 3db35f37d6dfc..8e4db55cb349c 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs @@ -1298,6 +1298,7 @@ static class B var comp = CreateCompilation(new[] { source, s_utils }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); if (expectedDiagnostics is null) { + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. CompileAndVerify(comp, expectedOutput: $"{expectedMethod}: {expectedType}"); } else @@ -1392,6 +1393,7 @@ static class B var comp = CreateCompilation(new[] { source, s_utils }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); if (expectedDiagnostics is null) { + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. CompileAndVerify(comp, expectedOutput: $"{expectedMethod}: {expectedType}"); } else @@ -1767,6 +1769,7 @@ static void Main() } }"; var comp = CreateCompilation(new[] { source, s_utils }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. CompileAndVerify(comp, expectedOutput: "System.Action, System.Action"); var tree = comp.SyntaxTrees[0]; @@ -7869,6 +7872,7 @@ static class E var comp = CreateCompilation(source, options: TestOptions.ReleaseExe); comp.VerifyDiagnostics(); + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. var verifier = CompileAndVerify(comp, expectedOutput: @"(41, 42)"); verifier.VerifyIL("Program.M1", @"{ diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs index 05fb0f4f61bbf..46673349d8a1c 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs @@ -3603,6 +3603,7 @@ unsafe static void Main() static T Goo(Action x) { throw null; } } "; + // TODO2 ILVerify succeeded var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.Fails).VerifyDiagnostics(); var tree = verifier.Compilation.SyntaxTrees.Single(); @@ -3630,6 +3631,7 @@ unsafe static void Main() static T Goo(Action x) { throw null; } } "; + // TODO2 ILVerify succeeded var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.Fails).VerifyDiagnostics(); var tree = verifier.Compilation.SyntaxTrees.Single(); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs index 467d8668094a5..2c828ee725973 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs @@ -3073,6 +3073,7 @@ static void M(string s) }"; var comp = CreateEmptyCompilation(text, new[] { reference1 }); + // TODO2 ILVerify succeeds CompileAndVerify(comp, verify: Verification.Fails). VerifyIL("C.M", @" { diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs index 8d653afb5bfbc..455394a7b610f 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs @@ -2646,6 +2646,7 @@ static void Test1(delegate*[] func) {} [Fact, WorkItem(50096, "https://github.com/dotnet/roslyn/issues/50096")] public void FunctionPointerInference_ExactInferenceThroughArray_RefKindMatch() { + // TODO2 ILVerify: Unexpected type on the stack. ImportCalli not implemented var verifier = CompileAndVerify(@" unsafe { diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs index 9c3bcbeaf1b2a..fd8ae9d0ac30e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs @@ -1440,7 +1440,7 @@ public class C // PE verification fails: [ : C::set_Property] Cannot change initonly field outside its .ctor. CompileAndVerify(comp, sourceSymbolValidator: symbolValidator, symbolValidator: symbolValidator, - verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails); + verify: Verification.Fails_InitOnly); void symbolValidator(ModuleSymbol m) { @@ -2732,7 +2732,7 @@ public int Property comp.VerifyDiagnostics(); // [ : C::set_Property] Cannot change initonly field outside its .ctor. CompileAndVerify(comp, expectedOutput: "42 43", - verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails); + verify: Verification.Fails_InitOnly); } [Fact] @@ -4181,7 +4181,7 @@ public static void Main() targetFramework: TargetFramework.Mscorlib40, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular9); // PEVerify: [ : S::set_Property] Cannot change initonly field outside its .ctor. CompileAndVerify(comp1, expectedOutput: "42", - verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails); + verify: Verification.Fails_InitOnly); var comp1Ref = new[] { comp1.ToMetadataReference() }; var comp7 = CreateCompilation(source2, references: comp1Ref, @@ -4205,7 +4205,7 @@ public readonly struct S { public int I { get; init; } } -" }, verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails, expectedOutput: "1"); +" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); @@ -4243,7 +4243,7 @@ public readonly struct S private readonly int i; public int I { get => i; init => i = value; } } -" }, verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails, expectedOutput: "1"); +" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); var s = verifier.Compilation.GetTypeByMetadataName("S"); var i = s.GetMember("I"); @@ -4282,7 +4282,7 @@ public struct S { public readonly int I { get; init; } } -" }, verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails, expectedOutput: "1"); +" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); var s = verifier.Compilation.GetTypeByMetadataName("S"); var i = s.GetMember("I"); @@ -4322,7 +4322,7 @@ public struct S private readonly int i; public readonly int I { get => i; init => i = value; } } -" }, verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails, expectedOutput: "1"); +" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); var s = verifier.Compilation.GetTypeByMetadataName("S"); var i = s.GetMember("I"); @@ -4417,7 +4417,7 @@ public int I2 } } } -" }, verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails, expectedOutput: @"I1 was 1 +" }, verify: Verification.Fails_InitOnly, expectedOutput: @"I1 was 1 I1 is 0"); var s = verifier.Compilation.GetTypeByMetadataName("S"); @@ -4551,7 +4551,7 @@ public record Container(Person Person); var comp = CreateCompilation(new[] { IsExternalInitTypeDefinition, source }, options: TestOptions.DebugExe); comp.VerifyEmitDiagnostics(); // PEVerify: Cannot change initonly field outside its .ctor. - CompileAndVerify(comp, expectedOutput: "c", verify: ExecutionConditionUtil.IsCoreClr ? Verification.Passes : Verification.Fails); + CompileAndVerify(comp, expectedOutput: "c", verify: Verification.Fails_InitOnly); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index a4828a4c4ca28..180bc3aa25569 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -3818,6 +3818,7 @@ class C var comp = CreateCompilation(new[] { source, interpolatedStringBuilder }, targetFramework: TargetFramework.NetCoreApp); + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var verifier = CompileAndVerify(comp, expectedOutput: @" value:S converted value:C"); @@ -9213,6 +9214,7 @@ public CustomHandler(int literalLength, int formattedCount," + refness + @" C c) var handler = GetInterpolatedStringCustomHandlerType("CustomHandler", "partial struct", useBoolReturns: true); + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var verifier = CompileAndVerify( new[] { code, InterpolatedStringHandlerArgumentAttribute, handler }, expectedOutput: "1literal:literal", diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs index a6fca5b9c53db..7aed838a83ff0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs @@ -772,6 +772,7 @@ static void Main() // default(IntPtr) as "load zero, convert to type", rather than making a stack slot and calling // init on it. + // TODO2 ILVerify succeeded var c = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails); c.VerifyIL("C.Main", @"{ diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 9ea714ca2560b..a4febe950f78a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -112195,6 +112195,7 @@ interface I2 compilation2.VerifyEmitDiagnostics(); // Verification against a corlib not named exactly mscorlib is expected to fail. + // TODO2 ILVerify succeeded CompileAndVerify(compilation2, verify: Verification.Fails); Assert.Equal(TypeKind.Struct, compilation2.GetTypeByMetadataName("A").TypeKind); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs index 4fc72d7c33b28..c20fc9a565a2e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs @@ -9037,6 +9037,7 @@ public static void RemoveDetail(this TMain main, TChild child) } }"; var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe); + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. CompileAndVerify(compilation, expectedOutput: @"RemoveDetail RemoveDetail @@ -11292,6 +11293,7 @@ private static bool Contains(this System.Collections.Generic.IEnumerable a throw new NotImplementedException(); }"; + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. CompileAndVerify(code, expectedOutput: @"2"); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index 6fe353dc666a5..1677f971e54e0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -6221,7 +6221,7 @@ static int CopyRefInt(ref int z) var compilation = CreateCompilation(program, options: TestOptions.DebugExe.WithAllowUnsafe(true)); compilation.VerifyDiagnostics( ); - var comp = CompileAndVerify(compilation, expectedOutput: "ok"); + var comp = CompileAndVerify(compilation, expectedOutput: "ok", verify: Verification.FailsIlVerify_TypedReference); } [Fact] @@ -6517,6 +6517,7 @@ unsafe static void Main() False"; var compilation = CreateCompilation(source, options: TestOptions.UnsafeReleaseExe); compilation.VerifyDiagnostics(); + // TODO2 ILVerify succeeded CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.Fails); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs index f0a96415b7ae9..562964a8cdf15 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs @@ -470,6 +470,7 @@ public static RGBColor FromRainbow(Rainbow colorBand) => var compilation = CreateCompilation(source, options: TestOptions.DebugExe); compilation.VerifyDiagnostics( ); + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs index 3a2f80d06c143..22c3946575619 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs @@ -2364,6 +2364,7 @@ public static void Main() "; var compilation = CreateCompilation(new[] { source, TestSources.Index }, options: TestOptions.ReleaseExe); compilation.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(compilation, expectedOutput: "123"); } @@ -3504,6 +3505,7 @@ public class C "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(compilation, expectedOutput: expectedOutput); } @@ -5051,6 +5053,7 @@ void M2() "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)"); verifier.VerifyIL("C.M", @" @@ -5139,6 +5142,7 @@ void M2() "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)"); verifier.VerifyIL("C.M", @" @@ -5228,6 +5232,7 @@ static void Main() Console.Write((x, y)); } }"; + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "Index Range (42, 43)"); } @@ -5267,6 +5272,7 @@ public void SlicePattern_String() System.Console.Write((first, rest).ToString()); } "; + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "(a, bc)"); } @@ -7068,6 +7074,7 @@ public string M() } } "; + // TODO2 ILVerify: Unexpected type on the stack. var verifier = CompileAndVerify(new[] { source, TestSources.Index }, options: TestOptions.DebugDll); verifier.VerifyIL("C.M", @" { @@ -7165,6 +7172,7 @@ public string M() } } "; + // TODO2 ILVerify: Unexpected type on the stack. var verifier = CompileAndVerify(new[] { source, TestSources.Index }); verifier.VerifyIL("C.M", @" { @@ -7314,6 +7322,7 @@ public void M() ); compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); + // TODO2 ILVerify: Unexpected type on the stack. var verifier = CompileAndVerify(compilation, expectedOutput: "(2, 3)"); verifier.VerifyDiagnostics(); // Note: no Index or Range involved @@ -7560,6 +7569,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(42, 42)"); } @@ -7606,6 +7616,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(42, 42)"); } @@ -7620,6 +7631,7 @@ public void Simple_String() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(4, 2)"); } @@ -7635,6 +7647,7 @@ public void Simple_Array() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(4, 2)"); } @@ -7656,6 +7669,7 @@ public void Simple_Array_VerifyIndexMaths(string data, string pattern, string el "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(4, 4)"); } @@ -7677,6 +7691,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(42, 42)"); } @@ -7698,6 +7713,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(42, 42)"); } @@ -7712,6 +7728,7 @@ public void Simple_String_Slice() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "42"); } @@ -7733,6 +7750,7 @@ public static void Main() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }, options: TestOptions.ReleaseExe); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. var verifier = CompileAndVerify(comp, expectedOutput: "(4, 2, 4, 2)"); // we use Array.Length to get the length, but should be using ldlen // Tracked by https://github.com/dotnet/roslyn/issues/57728 @@ -7825,6 +7843,7 @@ public void Simple_Array_Slice_VerifyRangeMaths(string data, string pattern, str "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }); comp.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Unexpected type on the stack. CompileAndVerify(comp, expectedOutput: "(4, 2, 2, 4, 2, 2)"); } @@ -7846,6 +7865,7 @@ public int M(int[] a) } "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }, options: TestOptions.ReleaseDll); + // TODO2 ILVerify: Unexpected type on the stack. var verifier = CompileAndVerify(comp).VerifyDiagnostics(); verifier.VerifyIL("C.M", @" diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs index ebf0618a26854..630552b84173a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs @@ -1885,7 +1885,7 @@ static void Main() "; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_1, options: TestOptions.DebugExe); comp.VerifyDiagnostics(); - CompileAndVerify(comp, expectedOutput: "123: True"); + CompileAndVerify(comp, expectedOutput: "123: True", verify: Verification.FailsIlVerify_TypedReference); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs index d1a03c60f4a71..8374c2b66d048 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs @@ -1024,6 +1024,7 @@ public static void Main(string[] args) { }" }); assembly.VerifyEmitDiagnostics(); + // TODO2 ILVerify: Assembly or module not found: a2 CompileAndVerify(assembly); } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs index 744421583f648..1c254215b3b28 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs @@ -48,6 +48,14 @@ private static Verification VerifyOnMonoOrCoreClr } } + private static Verification VerifyOnMonoOrCoreClr_NotVisible + { + get + { + return ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify_NotVisible : Verification.Skipped; + } + } + private void ValidateMethodImplementation_011(string source) { foreach (string access in new[] { "x.M1();", "new System.Action(x.M1)();" }) @@ -9638,7 +9646,7 @@ static void Main() M2 M3", symbolValidator: validate, - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); validate(compilation1.SourceModule); @@ -9702,7 +9710,7 @@ static void Main() CompileAndVerify(compilation4, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1 M2", - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -17954,7 +17962,7 @@ static void Main() get_P6 set_P6", symbolValidator: validate, - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); validate(compilation1.SourceModule); @@ -18063,7 +18071,7 @@ static void Main() set_P5 set_P6 ", - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -18075,7 +18083,7 @@ static void Main() get_P5 set_P6 ", - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation6 = CreateCompilation(source5, options: TestOptions.DebugExe, references: new[] { reference }, @@ -28444,7 +28452,7 @@ static void Main() get_P2 set_P2 get_P3 -set_P3", symbolValidator: validate, verify: VerifyOnMonoOrCoreClr); +set_P3", symbolValidator: validate, verify: VerifyOnMonoOrCoreClr_NotVisible); validate(compilation1.SourceModule); @@ -28517,7 +28525,7 @@ static void Main() set_P1 get_P2 set_P2", - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29259,7 +29267,7 @@ public void M1() } "; - ValidateNestedTypes_01(source0 + source1, Accessibility.Protected, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr); + ValidateNestedTypes_01(source0 + source1, Accessibility.Protected, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation1 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular, @@ -29365,7 +29373,7 @@ public void M1() I1+T3 B I1+T5", - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation5 = CreateCompilation(source2, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29500,7 +29508,7 @@ public void M1() I1+T3 B I1+T5", - verify: VerifyOnMonoOrCoreClr); + verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation5 = CreateCompilation(source2, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29809,7 +29817,7 @@ public void M1() } } "; - ValidateNestedTypes_01(source0 + source1, Accessibility.ProtectedAndInternal, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr); + ValidateNestedTypes_01(source0 + source1, Accessibility.ProtectedAndInternal, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_NotVisible); var compilation1 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular, @@ -32819,7 +32827,7 @@ static void Main() @"I2.M1 I4.M1 ", - verify: VerifyOnMonoOrCoreClr, + verify: VerifyOnMonoOrCoreClr_NotVisible, symbolValidator: ValidateMethodImplementationInDerived_01); foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) @@ -33065,7 +33073,7 @@ static void Main() @"I2.M1 I4.M1 ", - verify: VerifyOnMonoOrCoreClr, + verify: VerifyOnMonoOrCoreClr_NotVisible, symbolValidator: ValidateMethodImplementationInDerived_01); foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) @@ -38928,7 +38936,7 @@ public static void Test() @"123 -2 ", - verify: VerifyOnMonoOrCoreClr, symbolValidator: validate); + verify: VerifyOnMonoOrCoreClr_NotVisible, symbolValidator: validate); var source2 = @" @@ -38950,7 +38958,7 @@ static void Main() parseOptions: TestOptions.Regular, targetFramework: TargetFramework.NetCoreApp); - CompileAndVerify(compilation2, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "1122" : null, verify: VerifyOnMonoOrCoreClr); + CompileAndVerify(compilation2, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "1122" : null, verify: VerifyOnMonoOrCoreClr_NotVisible); } var source3 = @@ -44779,7 +44787,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); var source2 = @" interface I2 : I3 @@ -44805,7 +44813,7 @@ static void Main() var compilation1 = CreateCompilation(source0 + source2, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation1.VerifyDiagnostics(); - CompileAndVerify(compilation1, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr); + CompileAndVerify(compilation1, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); var source3 = @" interface I2 : I3 @@ -44942,8 +44950,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr); - + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); var source3 = @" class I2 @@ -45003,7 +45010,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); } private const string NoPiaAttributes = @" @@ -45463,6 +45470,7 @@ void ITest33.M1(){} var piaCompilation = CreateCompilation(pia, options: TestOptions.ReleaseDll, references: new[] { attributesRef }, targetFramework: TargetFramework.NetCoreApp); + // TODO2 ILVerify: Missing method 'Void UsePia.Test(ITest33)' CompileAndVerify(piaCompilation, verify: VerifyOnMonoOrCoreClr); string consumer1 = @" @@ -45516,7 +45524,7 @@ public interface ITest33 foreach (var reference2 in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) { var compilation2 = CreateCompilation(consumer2, options: TestOptions.ReleaseExe, references: new[] { reference2, pia2Reference }, targetFramework: TargetFramework.StandardLatest); - CompileAndVerify(compilation2, expectedOutput: "Test.M1"); + CompileAndVerify(compilation2, expectedOutput: "Test.M1", verify: Verification.Passes); } } } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index b61e95e596e74..02bba253b2c5d 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -6072,6 +6072,7 @@ class A {} s_mod2.GetReference(), }); + // TODO2 ILVerify: Assembly or module not found: ErrTestMod02 CompileAndVerify(comp).VerifyDiagnostics(); } diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index 2a328113cbecc..bd3eb1baf003b 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -37,6 +37,10 @@ public enum Verification // ILVerify errors TypedReference = 1 << 12, NotImplemented = 1 << 13, + NotVisible = 1 << 14, + + // Both + InitOnly = 1 << 15, // PEVerify errors TypeLoadFailed = 1 << 4, @@ -50,8 +54,11 @@ public enum Verification Passes = PassesPeVerify | PassesIlVerify, Fails = FailsPeVerify | FailsIlVerify, + Fails_InitOnly = FailsPeVerify | FailsIlVerify | InitOnly, // Cannot change initonly field outside its .ctor. + FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify | TypedReference, // ILVerify doesn't support TypedReference FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify | NotImplemented, // ILVerify has some un-implemented cases in EcmaModule.GetType + FailsIlVerify_NotVisible = PassesPeVerify | FailsIlVerify | NotVisible, // ILVerify: Type|Method|Field is not visible. FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify | TypeLoadFailed, // ILVerify doesn't complain type load failed FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify | UnexpectedTypeOnStack, // ILVerify doesn't complain about: Unexpected type on the stack. diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 1d2836b344409..4f6258b8637da 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -189,6 +189,16 @@ public void Verify(Verification verification) { throw new Exception("Expected: The method or operation is not implemented."); } + if ((verification & Verification.InitOnly) != 0 + && !message.Contains("Cannot change initonly field outside its .ctor.")) + { + throw new Exception("Expected: Cannot change initonly field outside its .ctor."); + } + if ((verification & Verification.NotVisible) != 0 + && !message.Contains(" is not visible.")) + { + throw new Exception("Expected: ... is not visible."); + } } else if ((verification & Verification.FailsIlVerify) != 0) { diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index 617da3c851ba9..8c19e85754765 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -357,6 +357,12 @@ public void Verify(Verification verification) { throw new Exception("Expected: was expected to contain an assembly manifest.", ex); } + if ((verification & Verification.InitOnly) != 0 + && !ex.Message.Contains("Cannot change initonly field outside its .ctor.")) + { + throw new Exception("Expected: Cannot change initonly field outside its .ctor."); + } + } } diff --git a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs index 386a40bac7e0a..e81c8339ff64f 100644 --- a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs +++ b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs @@ -839,6 +839,7 @@ Action translate(Action action) } } + // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. return CompileAndVerifyCommon( compilation, manifestResources, From eea70d36bf5666189ea07f0f5f51da682718e587 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 10:42:06 -0800 Subject: [PATCH 15/51] MissingStringType --- .../Emit/Attributes/AttributeTests_Dynamic.cs | 4 +-- .../Test/Emit/CodeGen/CodeGenMscorlib.cs | 8 +++--- .../Symbol/Compilation/UsedAssembliesTests.cs | 6 ++--- .../DefaultInterfaceImplementationTests.cs | 2 +- .../Symbol/Symbols/ExtensionMethodTests.cs | 15 ++++++----- src/Compilers/Test/Core/CommonTestBase.cs | 6 ++++- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 26 +++++++++++++++++-- 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index e06e8b7749f40..d746afff94d78 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1156,8 +1156,8 @@ static void Main() comp.VerifyDiagnostics(); // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. - // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); + // ILVerify: Failed to load type 'System.String' from assembly ... + CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs index dfbcc3116b3c2..bbb1bda34183b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs @@ -749,8 +749,8 @@ void Main() // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS (_VALUETYPE) in signature is a ValueType (Class,respectively). // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS(_VALUETYPE) in signature is a ValueType (Class, respectively). // Type load failed. - // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). + // ILVerify: Failed to load type 'System.String' from assembly ... + CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType). VerifyIL("program.Main()", @" { @@ -878,8 +878,8 @@ void Main() // fields of certain clr-ambiguous structs (only possible when building mscorlib) // PEVerify: Type load failed. - // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). + // ILVerify: Failed to load type 'System.String' from assembly ... + CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType). VerifyIL("System.IntPtr..ctor(int)", @" { // Code size 10 (0xa) diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs index 4e7b87b4dd92b..43708a2bd286a 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs @@ -32,7 +32,7 @@ interface I1 } "; var comp1 = CreateEmptyCompilation(source); - CompileAndVerify(comp1); + CompileAndVerify(comp1, verify: Verification.FailsIlVerify_MissingStringType); Assert.Empty(comp1.GetUsedAssemblyReferences()); @@ -53,7 +53,7 @@ public interface I1 } "; var comp1 = CreateEmptyCompilation(source); - CompileAndVerify(comp1); + CompileAndVerify(comp1, verify: Verification.FailsIlVerify_MissingStringType); var source2 = @" @@ -411,7 +411,7 @@ public interface I1 } "; var comp1 = CreateEmptyCompilation(source); - CompileAndVerify(comp1); + CompileAndVerify(comp1, verify: Verification.FailsIlVerify_MissingStringType); var source2 = @" diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs index 1c254215b3b28..d9d63009774b4 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs @@ -18083,7 +18083,7 @@ static void Main() get_P5 set_P6 ", - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr); var compilation6 = CreateCompilation(source5, options: TestOptions.DebugExe, references: new[] { reference }, diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs index b55e4e942dc56..6f1c6f6d2eeac 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs @@ -294,7 +294,7 @@ static void Goo(this string x) @"ABC 123 123 -xyz"); +xyz", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); } [WorkItem(541143, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541143")] @@ -376,7 +376,7 @@ static void Main() static void Goo(this T x) { } } "; - CompileAndVerify(source, expectedOutput: "2"); + CompileAndVerify(source, expectedOutput: "2", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); } [WorkItem(528426, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/528426")] @@ -873,7 +873,7 @@ internal static void F(this object o) { } internal static void F(this object x, object y) { } internal static void G(this object x, object y) { } }"; - var compilation = CompileAndVerify(source); + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); compilation.VerifyIL("N.C.M", @"{ // Code size 71 (0x47) @@ -939,7 +939,7 @@ internal static void F2(this object x, object y) { } internal static void F3(this object x, int y) { } internal static void F4(this object x, object y) { } }"; - var compilation = CompileAndVerify(source); + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); compilation.VerifyIL("N.C.M", @" { @@ -1923,7 +1923,7 @@ public static void M(this C c, int i) System.Console.Write(c.P * i); } }"; - CompileAndVerify(source, expectedOutput: "6"); + CompileAndVerify(source, expectedOutput: "6", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); } [Fact] @@ -2293,11 +2293,12 @@ static void M(Action a) a(); } }"; + // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. var compilation = CompileAndVerify(source, expectedOutput: @"F: System.Int32 F: S G: System.Int32 -G: S"); +G: S", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); compilation.VerifyIL("C.Main", @"{ // Code size 105 (0x69) @@ -2378,7 +2379,7 @@ internal static void M(this object o) System.Object System.Int32 B -B"); +B", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); compilation.VerifyIL("C.M", @"{ // Code size 112 (0x70) diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index bd3eb1baf003b..6a436a87844d4 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -38,9 +38,11 @@ public enum Verification TypedReference = 1 << 12, NotImplemented = 1 << 13, NotVisible = 1 << 14, + UnrecognizedArgDelegate = 1 << 15, + MissingStringType = 1 << 16, // Both - InitOnly = 1 << 15, + InitOnly = 1 << 17, // PEVerify errors TypeLoadFailed = 1 << 4, @@ -59,6 +61,8 @@ public enum Verification FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify | TypedReference, // ILVerify doesn't support TypedReference FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify | NotImplemented, // ILVerify has some un-implemented cases in EcmaModule.GetType FailsIlVerify_NotVisible = PassesPeVerify | FailsIlVerify | NotVisible, // ILVerify: Type|Method|Field is not visible. + FailsIlVerify_UnrecognizedArgDelegate = PassesPeVerify | FailsIlVerify | UnrecognizedArgDelegate, // ILVerify: Unrecognized arguments for delegate .ctor. + FailsIlVerify_MissingStringType = PassesPeVerify | FailsIlVerify | MissingStringType, // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify | TypeLoadFailed, // ILVerify doesn't complain type load failed FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify | UnexpectedTypeOnStack, // ILVerify doesn't complain about: Unexpected type on the stack. diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 4f6258b8637da..4f5f2905ccb43 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -166,7 +166,24 @@ public void Verify(Verification verification) var metadataReader = resolver.Resolve(name).GetMetadataReader(); if (metadataReader.AssemblyReferences.Count == 0) { - verifier.SetSystemModuleName(new AssemblyName(name)); + try + { + verifier.SetSystemModuleName(new AssemblyName(name)); + } + catch (Exception ex) + { + // ILVerify checks that corlib contains certain types + if ((verification & Verification.MissingStringType) != 0) + { + if (!ex.Message.Contains("Failed to load type 'System.String' from assembly")) + { + throw new Exception("Expected: Failed to load type 'System.String' from assembly ..."); + } + return; + } + + throw; + } } } } @@ -195,10 +212,15 @@ public void Verify(Verification verification) throw new Exception("Expected: Cannot change initonly field outside its .ctor."); } if ((verification & Verification.NotVisible) != 0 - && !message.Contains(" is not visible.")) + && !message.Contains(" is not visible.")) { throw new Exception("Expected: ... is not visible."); } + if ((verification & Verification.UnrecognizedArgDelegate) != 0 + && !message.Contains("Unrecognized arguments for delegate .ctor.")) + { + throw new Exception("Expected: Unrecognized arguments for delegate .ctor."); + } } else if ((verification & Verification.FailsIlVerify) != 0) { From d328e27d28e88526843f5177a821da92dc2b76c2 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 11:03:14 -0800 Subject: [PATCH 16/51] MissingAssembly --- .../Test/Emit/Attributes/AttributeTests_Assembly.cs | 4 ++-- .../CSharp/Test/Emit/Emit/EmitMetadataTests.cs | 4 ++-- .../Test/Symbol/Compilation/CompilationAPITests.cs | 4 ++-- .../Symbols/DefaultInterfaceImplementationTests.cs | 3 ++- .../CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs | 4 ++-- src/Compilers/Test/Core/CommonTestBase.cs | 11 ++++++++--- .../Platform/CoreClr/CoreCLRRuntimeEnvironment.cs | 7 ++++++- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 6368a1d45a53b..9c4de08778688 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -544,9 +544,9 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); - // TODO2 ILVerify: Assembly or module not found: hash_module + // ILVerify: Assembly or module not found: hash_module CompileAndVerify(compilation, - verify: Verification.Passes, + verify: Verification.FailsIlVerify_MissingAssembly, manifestResources: hash_resources, validator: (peAssembly) => { diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs index a46dc405b9ae9..ae62c117a554d 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs @@ -243,8 +243,8 @@ public class Test : Class1 } "; // modules not supported in ref emit - // TODO2 ILVerify: Assembly or module not found: netModule1 - CompileAndVerify(source, new[] { netModule1, netModule2 }, assemblyValidator: (assembly) => + // ILVerify: Assembly or module not found: netModule1 + CompileAndVerify(source, new[] { netModule1, netModule2 }, verify: Verification.FailsIlVerify_MissingAssembly, assemblyValidator: (assembly) => { Assert.Equal(3, assembly.Modules.Length); diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs index 8374c2b66d048..354a057591127 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs @@ -1024,8 +1024,8 @@ public static void Main(string[] args) { }" }); assembly.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Assembly or module not found: a2 - CompileAndVerify(assembly); + // ILVerify: Assembly or module not found: a2 + CompileAndVerify(assembly, verify: Verification.FailsIlVerify_MissingAssembly); } [WorkItem(713356, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/713356")] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs index d9d63009774b4..d7ab72b4a34fe 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs @@ -45524,7 +45524,8 @@ public interface ITest33 foreach (var reference2 in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) { var compilation2 = CreateCompilation(consumer2, options: TestOptions.ReleaseExe, references: new[] { reference2, pia2Reference }, targetFramework: TargetFramework.StandardLatest); - CompileAndVerify(compilation2, expectedOutput: "Test.M1", verify: Verification.Passes); + // ILVerify: Missing method 'Void UsePia.Test(ITest33)' + CompileAndVerify(compilation2, expectedOutput: "Test.M1", verify: Verification.Skipped); } } } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index 02bba253b2c5d..3a3f6aa331ca5 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -6072,8 +6072,8 @@ class A {} s_mod2.GetReference(), }); - // TODO2 ILVerify: Assembly or module not found: ErrTestMod02 - CompileAndVerify(comp).VerifyDiagnostics(); + // ILVerify: Assembly or module not found: ErrTestMod02 + CompileAndVerify(comp, verify: Verification.FailsIlVerify_MissingAssembly).VerifyDiagnostics(); } [Fact()] diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index 6a436a87844d4..8cdcf813e2e2e 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -40,9 +40,10 @@ public enum Verification NotVisible = 1 << 14, UnrecognizedArgDelegate = 1 << 15, MissingStringType = 1 << 16, + MissingAssembly = 1 << 17, // Both - InitOnly = 1 << 17, + InitOnly = 1 << 18, // PEVerify errors TypeLoadFailed = 1 << 4, @@ -56,14 +57,18 @@ public enum Verification Passes = PassesPeVerify | PassesIlVerify, Fails = FailsPeVerify | FailsIlVerify, - Fails_InitOnly = FailsPeVerify | FailsIlVerify | InitOnly, // Cannot change initonly field outside its .ctor. - + // ILVerify errors FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify | TypedReference, // ILVerify doesn't support TypedReference FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify | NotImplemented, // ILVerify has some un-implemented cases in EcmaModule.GetType FailsIlVerify_NotVisible = PassesPeVerify | FailsIlVerify | NotVisible, // ILVerify: Type|Method|Field is not visible. FailsIlVerify_UnrecognizedArgDelegate = PassesPeVerify | FailsIlVerify | UnrecognizedArgDelegate, // ILVerify: Unrecognized arguments for delegate .ctor. FailsIlVerify_MissingStringType = PassesPeVerify | FailsIlVerify | MissingStringType, // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... + FailsIlVerify_MissingAssembly = PassesPeVerify | FailsIlVerify | MissingAssembly, // ILVerify: Assembly or module not found: ... + // Both + Fails_InitOnly = FailsPeVerify | FailsIlVerify | InitOnly, // Cannot change initonly field outside its .ctor. + + // PEVerify errors FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify | TypeLoadFailed, // ILVerify doesn't complain type load failed FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify | UnexpectedTypeOnStack, // ILVerify doesn't complain about: Unexpected type on the stack. FailsPeVerify_UnableToResolveToken = FailsPeVerify | PassesIlVerify | UnableToResolveToken, // ILVerify doesn't complain about "unable to resolve token" diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 4f5f2905ccb43..973d3e801eda2 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -194,7 +194,7 @@ public void Verify(Verification verification) string message = string.Join("\r\n", result.Select(r => r.Message)); if ((verification & Verification.PassesIlVerify) != 0) { - throw new Exception("IL Verify failed: \r\n" + message); + throw new Exception("IL Verify failed expectedly: \r\n" + message); } if ((verification & Verification.TypedReference) != 0 && !message.Contains("TypedReference not supported in .NET Core")) @@ -221,6 +221,11 @@ public void Verify(Verification verification) { throw new Exception("Expected: Unrecognized arguments for delegate .ctor."); } + if ((verification & Verification.MissingAssembly) != 0 + && !message.Contains("Assembly or module not found: ")) + { + throw new Exception("Expected: Assembly or module not found: ..."); + } } else if ((verification & Verification.FailsIlVerify) != 0) { From ebbc74af2c53ab67c0848d1927e37feab4bf40bd Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 11:38:18 -0800 Subject: [PATCH 17/51] BadReturnType --- .../Attributes/AttributeTests_Synthesized.cs | 9 ++- .../Test/Emit/CodeGen/CodeGenForEachTests.cs | 36 +++++------ .../BindingAsyncTasklikeMoreTests.cs | 4 +- .../Semantic/Semantics/InterpolationTests.cs | 8 +-- .../Semantics/PatternMatchingTests3.cs | 4 +- .../PatternMatchingTests_ListPatterns.cs | 63 +++++++------------ src/Compilers/Test/Core/CommonTestBase.cs | 6 +- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 33 +++++++++- .../Test/Utilities/CSharp/CSharpTestBase.cs | 1 - 9 files changed, 92 insertions(+), 72 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index d9dccd29ba966..5363fcb84ed3e 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -954,8 +954,13 @@ public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(Ou } else { - // TODO2 Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly - CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.FailsPeVerify_MissingManifest : Verification.Passes, symbolValidator: module => + // ILVerify: Failed to load type 'System.String' from assembly + // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid + var verify = outputKind.IsNetModule() + ? Verification.FailsPeVerify_MissingManifest + : Verification.FailsIlVerify_MissingStringType; + + CompileAndVerify(compilation, verify: verify, symbolValidator: module => { var assemblyAttributes = module.ContainingAssembly.GetAttributes(); Assert.Equal(0, assemblyAttributes.Length); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs index 30c5d89bf344d..1cbc296dbcb5a 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs @@ -1384,8 +1384,8 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose() { System.Console.WriteLine(""Done with DisposableEnumerator""); } }"; - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, expectedOutput: @" + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" 1 2 3 @@ -1448,8 +1448,8 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose(params object[] args) { System.Console.WriteLine($""Done with DisposableEnumerator. args was {args}, length {args.Length}""); } }"; - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, expectedOutput: @" + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" 1 2 3 @@ -1483,8 +1483,8 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose(int arg = 1) { System.Console.WriteLine($""Done with DisposableEnumerator. arg was {arg}""); } }"; - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, expectedOutput: @" + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" 1 2 3 @@ -1524,8 +1524,8 @@ static class DisposeExtension } "; // extension methods do not contribute to disposal - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, expectedOutput: @"123"); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); } [Fact] @@ -1565,8 +1565,8 @@ static class DisposeExtension2 } "; // extension methods do not contribute to disposal - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, expectedOutput: @"123"); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); } [Fact] @@ -1602,8 +1602,8 @@ static class DisposeExtension } "; // extension methods do not contribute to disposal - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, expectedOutput: @"123"); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); } [Fact] @@ -1639,8 +1639,8 @@ static class DisposeExtension } "; // extension methods do not contribute to disposal - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, expectedOutput: @"123"); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); } [Fact] @@ -1736,8 +1736,8 @@ ref struct DisposableEnumerator public bool MoveNext() { return ++x < 4; } public void Dispose() { System.Console.WriteLine(""Done with DisposableEnumerator""); } }"; - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, parseOptions: TestOptions.Regular7_3, expectedOutput: @" + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var compilation = CompileAndVerify(source, parseOptions: TestOptions.Regular7_3, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" 1 2 3"); @@ -4733,8 +4733,8 @@ ref struct Enumerator public bool MoveNext() => Current++ != 3; public void Dispose() { Console.Write(""Disposed""); } }"; - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, parseOptions: TestOptions.Regular9, expectedOutput: @"123Disposed") + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + CompileAndVerify(source, parseOptions: TestOptions.Regular9, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123Disposed") .VerifyIL("C.Main", @" { // Code size 45 (0x2d) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs index a0493340e1057..cb77b4058acae 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs @@ -1587,8 +1587,8 @@ public static void M(MyResult r) var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); compilation.VerifyDiagnostics(); - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(compilation, expectedOutput: "3"); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + CompileAndVerify(compilation, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: "3"); compilation = CreateCompilation(source, options: TestOptions.DebugExe); compilation.VerifyDiagnostics(); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 180bc3aa25569..fb6c35a14e567 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -3818,8 +3818,8 @@ class C var comp = CreateCompilation(new[] { source, interpolatedStringBuilder }, targetFramework: TargetFramework.NetCoreApp); - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var verifier = CompileAndVerify(comp, expectedOutput: @" + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" value:S converted value:C"); @@ -9214,13 +9214,13 @@ public CustomHandler(int literalLength, int formattedCount," + refness + @" C c) var handler = GetInterpolatedStringCustomHandlerType("CustomHandler", "partial struct", useBoolReturns: true); - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. var verifier = CompileAndVerify( new[] { code, InterpolatedStringHandlerArgumentAttribute, handler }, expectedOutput: "1literal:literal", symbolValidator: validator, sourceSymbolValidator: validator, - verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.Passes : Verification.Skipped); + verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify_BadReturnType : Verification.Skipped); verifier.VerifyIL("", refness == "in" ? @" { // Code size 46 (0x2e) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs index 562964a8cdf15..bc391bcfbb73a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs @@ -470,8 +470,8 @@ public static RGBColor FromRainbow(Rainbow colorBand) => var compilation = CreateCompilation(source, options: TestOptions.DebugExe); compilation.VerifyDiagnostics( ); - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var comp = CompileAndVerify(compilation, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: expectedOutput); } [Fact, WorkItem(35278, "https://github.com/dotnet/roslyn/issues/35278")] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs index 22c3946575619..005a57db82f60 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs @@ -2364,8 +2364,7 @@ public static void Main() "; var compilation = CreateCompilation(new[] { source, TestSources.Index }, options: TestOptions.ReleaseExe); compilation.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(compilation, expectedOutput: "123"); + CompileAndVerify(compilation, expectedOutput: "123", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -3505,8 +3504,7 @@ public class C "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(compilation, expectedOutput: expectedOutput); + CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -5053,8 +5051,7 @@ void M2() "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)"); + var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); verifier.VerifyIL("C.M", @" { @@ -5142,8 +5139,7 @@ void M2() "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)"); + var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); verifier.VerifyIL("C.M", @" { @@ -5232,8 +5228,7 @@ static void Main() Console.Write((x, y)); } }"; - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "Index Range (42, 43)"); + CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "Index Range (42, 43)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -5272,8 +5267,7 @@ public void SlicePattern_String() System.Console.Write((first, rest).ToString()); } "; - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "(a, bc)"); + CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "(a, bc)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7074,8 +7068,7 @@ public string M() } } "; - // TODO2 ILVerify: Unexpected type on the stack. - var verifier = CompileAndVerify(new[] { source, TestSources.Index }, options: TestOptions.DebugDll); + var verifier = CompileAndVerify(new[] { source, TestSources.Index }, options: TestOptions.DebugDll, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); verifier.VerifyIL("C.M", @" { // Code size 105 (0x69) @@ -7172,8 +7165,7 @@ public string M() } } "; - // TODO2 ILVerify: Unexpected type on the stack. - var verifier = CompileAndVerify(new[] { source, TestSources.Index }); + var verifier = CompileAndVerify(new[] { source, TestSources.Index }, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); verifier.VerifyIL("C.M", @" { // Code size 78 (0x4e) @@ -7322,8 +7314,7 @@ public void M() ); compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); - // TODO2 ILVerify: Unexpected type on the stack. - var verifier = CompileAndVerify(compilation, expectedOutput: "(2, 3)"); + var verifier = CompileAndVerify(compilation, expectedOutput: "(2, 3)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); verifier.VerifyDiagnostics(); // Note: no Index or Range involved verifier.VerifyIL("C.M", @" @@ -7569,8 +7560,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(42, 42)"); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7616,8 +7606,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(42, 42)"); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7631,8 +7620,7 @@ public void Simple_String() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(4, 2)"); + CompileAndVerify(comp, expectedOutput: "(4, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7647,8 +7635,7 @@ public void Simple_Array() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(4, 2)"); + CompileAndVerify(comp, expectedOutput: "(4, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Theory] @@ -7669,8 +7656,7 @@ public void Simple_Array_VerifyIndexMaths(string data, string pattern, string el "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(4, 4)"); + CompileAndVerify(comp, expectedOutput: "(4, 4)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7691,8 +7677,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(42, 42)"); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7713,8 +7698,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(42, 42)"); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7728,8 +7712,7 @@ public void Simple_String_Slice() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "42"); + CompileAndVerify(comp, expectedOutput: "42", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact, WorkItem(57728, "https://github.com/dotnet/roslyn/issues/57728")] @@ -7750,8 +7733,7 @@ public static void Main() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }, options: TestOptions.ReleaseExe); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - var verifier = CompileAndVerify(comp, expectedOutput: "(4, 2, 4, 2)"); + var verifier = CompileAndVerify(comp, expectedOutput: "(4, 2, 4, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); // we use Array.Length to get the length, but should be using ldlen // Tracked by https://github.com/dotnet/roslyn/issues/57728 verifier.VerifyIL("C.Main", @" @@ -7843,8 +7825,7 @@ public void Simple_Array_Slice_VerifyRangeMaths(string data, string pattern, str "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }); comp.VerifyEmitDiagnostics(); - // TODO2 ILVerify: Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "(4, 2, 2, 4, 2, 2)"); + CompileAndVerify(comp, expectedOutput: "(4, 2, 2, 4, 2, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] @@ -7865,8 +7846,8 @@ public int M(int[] a) } "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }, options: TestOptions.ReleaseDll); - // TODO2 ILVerify: Unexpected type on the stack. - var verifier = CompileAndVerify(comp).VerifyDiagnostics(); + // ILVerify: Unexpected type on the stack. { Offset = 20, Found = readonly address of '[...]System.Index', Expected = address of '[...]System.Index' } + var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack).VerifyDiagnostics(); verifier.VerifyIL("C.M", @" { @@ -7942,7 +7923,7 @@ class C : Interface } "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); - var verifier = CompileAndVerify(comp, expectedOutput: "(42, 43)"); + var verifier = CompileAndVerify(comp, expectedOutput: "(42, 43)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); verifier.VerifyDiagnostics(); } diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index 8cdcf813e2e2e..d28dacc82a4d8 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -41,9 +41,11 @@ public enum Verification UnrecognizedArgDelegate = 1 << 15, MissingStringType = 1 << 16, MissingAssembly = 1 << 17, + UnexpectedReadonlyAddressOnStack = 1 << 18, + BadReturnType = 1 << 19, // Both - InitOnly = 1 << 18, + InitOnly = 1 << 20, // PEVerify errors TypeLoadFailed = 1 << 4, @@ -64,6 +66,8 @@ public enum Verification FailsIlVerify_UnrecognizedArgDelegate = PassesPeVerify | FailsIlVerify | UnrecognizedArgDelegate, // ILVerify: Unrecognized arguments for delegate .ctor. FailsIlVerify_MissingStringType = PassesPeVerify | FailsIlVerify | MissingStringType, // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... FailsIlVerify_MissingAssembly = PassesPeVerify | FailsIlVerify | MissingAssembly, // ILVerify: Assembly or module not found: ... + FailsIlVerify_UnexpectedReadonlyAddressOnStack = PassesPeVerify | FailsIlVerify | UnexpectedReadonlyAddressOnStack, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } + FailsIlVerify_BadReturnType = PassesPeVerify | FailsIlVerify | BadReturnType, // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. // Both Fails_InitOnly = FailsPeVerify | FailsIlVerify | InitOnly, // Cannot change initonly field outside its .ctor. diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 973d3e801eda2..3ce9b4061b2de 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -18,6 +18,8 @@ using System.Reflection; using System.Reflection.Metadata; using Roslyn.Test.Utilities; +using Microsoft.CodeAnalysis.PooledObjects; +using System.Diagnostics.Tracing; namespace Roslyn.Test.Utilities.CoreClr { @@ -191,7 +193,7 @@ public void Verify(Verification verification) var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); if (result.Count() > 0) { - string message = string.Join("\r\n", result.Select(r => r.Message)); + string message = printVerificationResult(result); if ((verification & Verification.PassesIlVerify) != 0) { throw new Exception("IL Verify failed expectedly: \r\n" + message); @@ -226,12 +228,41 @@ public void Verify(Verification verification) { throw new Exception("Expected: Assembly or module not found: ..."); } + if ((verification & Verification.UnexpectedReadonlyAddressOnStack) != 0 + && !(message.Contains("Unexpected type on the stack.") + && message.Contains("Found = readonly address of") + && message.Contains("Expected = address of"))) + { + throw new Exception("Expected: Assembly or module not found: ..."); + } } else if ((verification & Verification.FailsIlVerify) != 0) { throw new Exception("IL Verify succeeded unexpectedly"); } } + + static string printVerificationResult(IEnumerable result) + { + return string.Join("\r\n", result.Select(r => r.Message + printErrorArguments(r.ErrorArguments))); + } + + static string printErrorArguments(ILVerify.ErrorArgument[] errorArguments) + { + if (errorArguments is null + || errorArguments.Length == 0) + { + return ""; + } + + var pooledBuilder = PooledStringBuilder.GetInstance(); + var builder = pooledBuilder.Builder; + builder.Append(" { "); + builder.AppendJoin(", ", errorArguments.Select(a => a.Name + " = " + a.Value.ToString())); + builder.Append(" }"); + + return pooledBuilder.ToStringAndFree(); + } } public string[] VerifyModules(string[] modulesToVerify) diff --git a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs index e81c8339ff64f..386a40bac7e0a 100644 --- a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs +++ b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs @@ -839,7 +839,6 @@ Action translate(Action action) } } - // TODO2 ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. return CompileAndVerifyCommon( compilation, manifestResources, From 66aa35b3ba599c18ca90061fed333dfeca7afad8 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 11:51:38 -0800 Subject: [PATCH 18/51] More --- .../Test/Emit/CodeGen/CodeGenStructsAndEnum.cs | 12 ++++++------ .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 14 ++++++++------ .../Test/Emit/Emit/CompilationEmitTests.cs | 4 ++-- .../Test/Semantic/Semantics/BetterCandidates.cs | 4 ++-- .../Semantics/BindingAsyncTasklikeMoreTests.cs | 2 +- .../Test/Semantic/Semantics/DelegateTypeTests.cs | 16 ++++++++-------- .../Test/Semantic/Semantics/DynamicTests.cs | 8 ++++---- .../Semantics/NullableReferenceTypesTests.cs | 2 +- .../Semantics/OverloadResolutionTests.cs | 8 ++++---- .../Semantic/Semantics/PatternMatchingTests.cs | 6 ++++-- .../Semantic/Semantics/SpanStackSafetyTests.cs | 3 ++- 11 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index fb027ea432f33..a845cfc9c96f9 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -259,8 +259,8 @@ static void Main(string[] args) } } "; - // TODO2 ILVerify: Unexpected type on the stack. - var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: @""); + // ILVerify: Unexpected type on the stack. { Offset = 20, Found = readonly address of '[...]S1', Expected = address of '[...]S1' } + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, expectedOutput: @""); compilation.VerifyIL("S1.Equals(object)", @" @@ -449,8 +449,8 @@ static void Main() } } "; - // TODO2 ILVerify: Unexpected type on the stack. - var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: @" + // ILVerify: Unexpected type on the stack. { Offset = 31, Found = readonly address of '[...]NS.N2.S`2', Expected = address of '[...]NS.N2.S`2' } + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, expectedOutput: @" Abc 255 q"); @@ -2367,8 +2367,8 @@ static void Main(string[] args) } "; - // TODO2 ILVerify: Unexpected type on the stack. - var compilation = CompileAndVerify(source, verify: Verification.Passes, expectedOutput: "0"); + // ILVerify: Unexpected type on the stack. { Offset = 10, Found = readonly address of '[...]C1', Expected = address of '[...]C1' } + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, expectedOutput: "0"); compilation.VerifyIL("Program.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 320cdca25fc41..32c947232241c 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -77,8 +77,8 @@ static void Main(object[] args) Console.WriteLine((((DoubleAndStruct)args[0]).y).x); } }"; - // TODO2 ILVerify: Unexpected type on the stack. - var result = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugDll); + // ILVerify: Unexpected type on the stack. { Offset = 59, Found = readonly address of '[...]DoubleAndStruct', Expected = address of '[...]DoubleAndStruct' } + var result = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -165,8 +165,8 @@ static void Main(object[] args) Console.WriteLine(((((OuterStruct)args[0]).z).y).x); } }"; - // TODO2 ILVerify: Unexpected type on the stack. - var result = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugDll); + // ILVerify: Unexpected type on the stack. { Offset = 34, Found = readonly address of '[...]OuterStruct', Expected = address of '[...]OuterStruct' } + var result = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -5261,8 +5261,10 @@ static void Test(in T r) } }"; - // TODO2 ILVerify: Unexpected type on the stack. - var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); + // ILVerify: + // Unexpected type on the stack. { Offset = 9, Found = readonly address of 'T', Expected = address of 'T' } + // Unexpected type on the stack. { Offset = 23, Found = readonly address of 'T', Expected = address of 'T' } + var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); var expectedIL = @" { diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 634475e666b25..0d2d51be37914 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -5231,8 +5231,8 @@ public void CompileAndVerifyModuleIncludesAllModules() var modRef = CreateCompilation("public class A { }", options: TestOptions.ReleaseModule, assemblyName: "refMod").EmitToImageReference(); var comp = CreateCompilation("public class B : A { }", references: new[] { modRef }, assemblyName: "sourceMod"); - // TODO2 ILVerify: Assembly or module not found: refMod - CompileAndVerify(comp, symbolValidator: module => + // ILVerify: Assembly or module not found: refMod + CompileAndVerify(comp, verify: Verification.FailsIlVerify_MissingAssembly, symbolValidator: module => { var b = module.GlobalNamespace.GetTypeMember("B"); Assert.Equal("B", b.Name); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs index d0594ce3bf86a..b2dcfa8dcbf1d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs @@ -862,8 +862,8 @@ public class ExtensionAttribute : System.Attribute {} ); var compilation = CreateCompilationWithBetterCandidates(source, options: TestOptions.ReleaseExe).VerifyDiagnostics( ); - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(compilation, expectedOutput: "2"); + // ILVerify: Unrecognized arguments for delegate .ctor. + CompileAndVerify(compilation, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: "2"); } // Test suggested by @VSadov diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs index cb77b4058acae..dad5b429f5bfe 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs @@ -1592,7 +1592,7 @@ public static void M(MyResult r) compilation = CreateCompilation(source, options: TestOptions.DebugExe); compilation.VerifyDiagnostics(); - CompileAndVerify(compilation, expectedOutput: "3"); + CompileAndVerify(compilation, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: "3"); } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs index 8e4db55cb349c..6356bc9ab5c1d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs @@ -1298,8 +1298,8 @@ static class B var comp = CreateCompilation(new[] { source, s_utils }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); if (expectedDiagnostics is null) { - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(comp, expectedOutput: $"{expectedMethod}: {expectedType}"); + // ILVerify: Unrecognized arguments for delegate .ctor. + CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: $"{expectedMethod}: {expectedType}"); } else { @@ -1393,8 +1393,8 @@ static class B var comp = CreateCompilation(new[] { source, s_utils }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); if (expectedDiagnostics is null) { - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(comp, expectedOutput: $"{expectedMethod}: {expectedType}"); + // ILVerify: Unrecognized arguments for delegate .ctor. + CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: $"{expectedMethod}: {expectedType}"); } else { @@ -1769,8 +1769,8 @@ static void Main() } }"; var comp = CreateCompilation(new[] { source, s_utils }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(comp, expectedOutput: "System.Action, System.Action"); + // ILVerify: Unrecognized arguments for delegate .ctor. + CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: "System.Action, System.Action"); var tree = comp.SyntaxTrees[0]; var model = comp.GetSemanticModel(tree); @@ -7872,8 +7872,8 @@ static class E var comp = CreateCompilation(source, options: TestOptions.ReleaseExe); comp.VerifyDiagnostics(); - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. - var verifier = CompileAndVerify(comp, expectedOutput: @"(41, 42)"); + // ILVerify: Unrecognized arguments for delegate .ctor. + var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: @"(41, 42)"); verifier.VerifyIL("Program.M1", @"{ // Code size 20 (0x14) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs index 46673349d8a1c..d517d5e9193a0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs @@ -3603,8 +3603,8 @@ unsafe static void Main() static T Goo(Action x) { throw null; } } "; - // TODO2 ILVerify succeeded - var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.Fails).VerifyDiagnostics(); + // PEVerify: [ : Program::Main][mdToken=0x6000001][offset 0x0000002C][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack. + var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics(); var tree = verifier.Compilation.SyntaxTrees.Single(); var model = verifier.Compilation.GetSemanticModel(tree); @@ -3631,8 +3631,8 @@ unsafe static void Main() static T Goo(Action x) { throw null; } } "; - // TODO2 ILVerify succeeded - var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.Fails).VerifyDiagnostics(); + // PEVerify: [ : Program::Main][mdToken=0x6000001][offset 0x0000002C][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack. + var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics(); var tree = verifier.Compilation.SyntaxTrees.Single(); var model = verifier.Compilation.GetSemanticModel(tree); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index a4febe950f78a..75471cbedd133 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -112196,7 +112196,7 @@ interface I2 // Verification against a corlib not named exactly mscorlib is expected to fail. // TODO2 ILVerify succeeded - CompileAndVerify(compilation2, verify: Verification.Fails); + CompileAndVerify(compilation2, verify: Verification.Passes); Assert.Equal(TypeKind.Struct, compilation2.GetTypeByMetadataName("A").TypeKind); Assert.Equal(TypeKind.Enum, compilation2.GetTypeByMetadataName("B").TypeKind); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs index c20fc9a565a2e..b1b6b33d44959 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs @@ -9037,8 +9037,8 @@ public static void RemoveDetail(this TMain main, TChild child) } }"; var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe); - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(compilation, expectedOutput: + // ILVerify: Unrecognized arguments for delegate .ctor. + CompileAndVerify(compilation, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: @"RemoveDetail RemoveDetail RemoveDetail @@ -11293,8 +11293,8 @@ private static bool Contains(this System.Collections.Generic.IEnumerable a throw new NotImplementedException(); }"; - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(code, expectedOutput: @"2"); + // ILVerify: Unrecognized arguments for delegate .ctor. + CompileAndVerify(code, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: @"2"); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index 1677f971e54e0..e9ec0bd2cd332 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -6517,8 +6517,10 @@ unsafe static void Main() False"; var compilation = CreateCompilation(source, options: TestOptions.UnsafeReleaseExe); compilation.VerifyDiagnostics(); - // TODO2 ILVerify succeeded - CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.Fails); + // PEVerify: + // [ : Program::Main][mdToken=0x6000001][offset 0x00000002] Unmanaged pointers are not a verifiable type. + // [ : Program::Main][mdToken= 0x6000001][offset 0x00000002] Unable to resolve token. + CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify_UnableToResolveToken); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs index ec4e43f9fc7ed..e47c4a0d1edcb 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs @@ -1850,7 +1850,8 @@ static void Main() "; CSharpCompilation comp = CreateCompilationWithMscorlibAndSpan(text, options: TestOptions.DebugExe); - CompileAndVerify(comp, expectedOutput: "Done").VerifyDiagnostics(); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + CompileAndVerify(comp, expectedOutput: "Done", verify: Verification.FailsIlVerify_BadReturnType).VerifyDiagnostics(); } [Fact] From c34aa280102247af473239448b1088768ae80764 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 12:43:05 -0800 Subject: [PATCH 19/51] More --- .../CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs | 3 ++- .../CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs | 3 +-- .../CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs | 4 ++-- .../CSharp/Test/Semantic/Semantics/ForEachTests.cs | 3 +-- .../CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs | 3 +-- .../Test/Semantic/Semantics/NullableReferenceTypesTests.cs | 5 ++--- src/Compilers/Test/Core/CommonTestBase.cs | 1 + .../Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs | 6 +++--- 10 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 9c4de08778688..f2e5a06318822 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -575,8 +575,9 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); + // ILVerify: Assembly or module not found: hash_module CompileAndVerify(compilation, - verify: Verification.Passes, + verify: Verification.FailsIlVerify_MissingAssembly, manifestResources: hash_resources, validator: (peAssembly) => { diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index d746afff94d78..58dc963818771 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1193,7 +1193,7 @@ static void Main() // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs index 250412f72658a..4819857ca19f2 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs @@ -6161,8 +6161,7 @@ public static async IAsyncEnumerator GetAsyncEnumerator(this Range range) options: TestOptions.DebugExe, parseOptions: TestOptions.Regular9); comp.VerifyDiagnostics(); - // TODO2 Unexpected type on the stack. - CompileAndVerify(comp, expectedOutput: "123"); + CompileAndVerify(comp, expectedOutput: "123", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs index 83560e57ba63b..e253c4874a5c6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs @@ -9603,7 +9603,7 @@ .locals init (int V_0, //a IL_0066: callvirt ""void <>A{00000004}.Invoke(System.Runtime.CompilerServices.CallSite, ref int, object)"" IL_006b: ret } -", verify: Verification.PassesPeVerify | Verification.FailsIlVerify); // ILVerify doesn't support TypedReference +", verify: Verification.FailsIlVerify_TypedReference); // ILVerify doesn't support TypedReference } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs index 7071fa514608b..d10679ea717c6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs @@ -5233,8 +5233,8 @@ public RefLike M() public ref struct RefLike{} } "; - // TODO: ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var verifier = CompileAndVerify(source, verify: Verification.Passes, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + var verifier = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- M --- ---"); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs index 2c828ee725973..e4919317c64aa 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs @@ -3073,8 +3073,7 @@ static void M(string s) }"; var comp = CreateEmptyCompilation(text, new[] { reference1 }); - // TODO2 ILVerify succeeds - CompileAndVerify(comp, verify: Verification.Fails). + CompileAndVerify(comp, verify: Verification.TypeLoadFailed). VerifyIL("C.M", @" { // Code size 28 (0x1c) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs index 7aed838a83ff0..f7bcb86a9d8ae 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs @@ -772,8 +772,7 @@ static void Main() // default(IntPtr) as "load zero, convert to type", rather than making a stack slot and calling // init on it. - // TODO2 ILVerify succeeded - var c = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails); + var c = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); c.VerifyIL("C.Main", @"{ // Code size 13 (0xd) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 75471cbedd133..cfc9bbc0dea86 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -112195,8 +112195,7 @@ interface I2 compilation2.VerifyEmitDiagnostics(); // Verification against a corlib not named exactly mscorlib is expected to fail. - // TODO2 ILVerify succeeded - CompileAndVerify(compilation2, verify: Verification.Passes); + CompileAndVerify(compilation2, verify: Verification.FailsPeVerify_TypeLoadFailed); Assert.Equal(TypeKind.Struct, compilation2.GetTypeByMetadataName("A").TypeKind); Assert.Equal(TypeKind.Enum, compilation2.GetTypeByMetadataName("B").TypeKind); @@ -112207,7 +112206,7 @@ interface I2 var compilation3 = CreateEmptyCompilation(source2, options: WithNullableEnable(TestOptions.ReleaseDll), references: new[] { compilation1.ToMetadataReference(), MinCorlibRef }); compilation3.VerifyEmitDiagnostics(); - CompileAndVerify(compilation3, verify: Verification.Fails); + CompileAndVerify(compilation3, verify: Verification.FailsPeVerify_TypeLoadFailed); Assert.Equal(TypeKind.Struct, compilation3.GetTypeByMetadataName("A").TypeKind); Assert.Equal(TypeKind.Enum, compilation3.GetTypeByMetadataName("B").TypeKind); diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index d28dacc82a4d8..f15abd9a31bdb 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -26,6 +26,7 @@ namespace Microsoft.CodeAnalysis.Test.Utilities [Flags] public enum Verification { + // TODO2 either it's Skipped, Passes, or we list specific failures // TODO2 simplify flags? Do we really need a Skipped? Skipped = 0, diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 3ce9b4061b2de..081bb0e34679b 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -196,7 +196,7 @@ public void Verify(Verification verification) string message = printVerificationResult(result); if ((verification & Verification.PassesIlVerify) != 0) { - throw new Exception("IL Verify failed expectedly: \r\n" + message); + throw new Exception("IL Verify failed unexpectedly: \r\n" + message); } if ((verification & Verification.TypedReference) != 0 && !message.Contains("TypedReference not supported in .NET Core")) @@ -230,8 +230,8 @@ public void Verify(Verification verification) } if ((verification & Verification.UnexpectedReadonlyAddressOnStack) != 0 && !(message.Contains("Unexpected type on the stack.") - && message.Contains("Found = readonly address of") - && message.Contains("Expected = address of"))) + && message.Contains("Found = readonly address of") + && message.Contains("Expected = address of"))) { throw new Exception("Expected: Assembly or module not found: ..."); } From d23c09cae2ac307934e29bf305b95cfb9920463f Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 13:29:48 -0800 Subject: [PATCH 20/51] Change design of flags --- .../Attributes/AttributeTests_Assembly.cs | 9 +- .../Emit/Attributes/AttributeTests_Dynamic.cs | 4 +- .../Attributes/AttributeTests_IsByRefLike.cs | 2 +- .../Test/Emit/CodeGen/CodeGenMscorlib.cs | 4 +- .../CodeGen/CodeGenOverridingAndHiding.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 5 +- .../CSharp/Test/Emit/CodeGen/UnsafeTests.cs | 6 +- .../Test/Emit/Emit/CompilationEmitTests.cs | 5 +- .../Test/Semantic/Semantics/ForEachTests.cs | 2 +- .../Semantics/FunctionPointerTests.cs | 4 +- src/Compilers/Test/Core/CommonTestBase.cs | 80 +++----- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 186 ++++++++++-------- .../Desktop/DesktopRuntimeEnvironment.cs | 66 ++++--- 13 files changed, 202 insertions(+), 173 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index f2e5a06318822..5e32eb5544a48 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -298,10 +298,9 @@ public void MismatchedSurrogateInAssemblyCultureAttribute() string s = @"[assembly: System.Reflection.AssemblyCultureAttribute(""\uD800"")]"; var comp = CreateCompilation(s, options: TestOptions.ReleaseDll); - // TODO2 // PEVerify: // Warning: Invalid locale string. - CompileAndVerify(comp, verify: Verification.Passes, symbolValidator: m => + CompileAndVerify(comp, verify: Verification.FailsPeVerify_UnspecifiedError, symbolValidator: m => { var utf8 = new System.Text.UTF8Encoding(false, false); Assert.Equal(utf8.GetString(utf8.GetBytes("\uD800")), m.ContainingAssembly.Identity.CultureName); @@ -607,7 +606,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.Passes, + verify: Verification.FailsIlVerify_MissingAssembly, manifestResources: hash_resources, validator: (peAssembly) => { @@ -637,7 +636,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.Passes, + verify: Verification.FailsIlVerify_MissingAssembly, manifestResources: hash_resources, validator: (peAssembly) => { @@ -768,7 +767,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module_Comp.EmitToImageReference() }); CompileAndVerify(compilation, - verify: Verification.Passes, + verify: Verification.FailsIlVerify_MissingAssembly, validator: (peAssembly) => { var peReader = peAssembly.ManifestModule.GetMetadataReader(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index 58dc963818771..0fd56d5a3d3af 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1157,7 +1157,7 @@ static void Main() // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. // ILVerify: Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType); + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType); } [Fact] @@ -1193,7 +1193,7 @@ static void Main() // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType); + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index 522355161fe77..acd34b8eeb722 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -957,7 +957,7 @@ public ref struct NotTypedReference { } }"; var compilation1 = CreateEmptyCompilation(source1, assemblyName: GetUniqueName()); - CompileAndVerify(compilation1, verify: Verification.FailsPeVerify, symbolValidator: module => + CompileAndVerify(compilation1, verify: Verification.FailsPeVerify_TypeLoadFailed, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("System.TypedReference"); AssertReferencedIsByRefLike(type, hasObsolete: false); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs index bbb1bda34183b..9f0a2a6f6aa48 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs @@ -750,7 +750,7 @@ void Main() // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS(_VALUETYPE) in signature is a ValueType (Class, respectively). // Type load failed. // ILVerify: Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType). + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType). VerifyIL("program.Main()", @" { @@ -879,7 +879,7 @@ void Main() // PEVerify: Type load failed. // ILVerify: Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify | Verification.TypeLoadFailed | Verification.FailsIlVerify | Verification.MissingStringType). + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType). VerifyIL("System.IntPtr..ctor(int)", @" { // Code size 10 (0xa) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs index c8cdde9923f16..b90346e2c0965 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs @@ -2556,7 +2556,7 @@ public static void Main() // from assembly 'Dev10, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' // is overriding a method that is not visible from that assembly. - CompileAndVerify(outerCompilation, verify: Verification.FailsPeVerify | Verification.PassesIlVerify).VerifyIL("Test.Main", @" + CompileAndVerify(outerCompilation, verify: Verification.FailsPeVerify_UnableToResolveToken).VerifyIL("Test.Main", @" { // Code size 65 (0x41) .maxstack 4 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 32c947232241c..bbc2925eb38b7 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -5261,10 +5261,13 @@ static void Test(in T r) } }"; + // PEVerify: + // [ : Program::GetElementRef[T]][mdToken=0x6000004][offset 0x00000009][found readonly address of ref ][expected address of ref ] Unexpected type on the stack. + // [ : Program::GetElementRef[T]][mdToken= 0x6000004][offset 0x00000017][found readonly address of ref ][expected address of ref ] Unexpected type on the stack. // ILVerify: // Unexpected type on the stack. { Offset = 9, Found = readonly address of 'T', Expected = address of 'T' } // Unexpected type on the stack. { Offset = 23, Found = readonly address of 'T', Expected = address of 'T' } - var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack | Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); var expectedIL = @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index 01fd8daa5c9af..a97a1ff2deedb 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -10334,7 +10334,7 @@ public static void Main() // PEVerify: // [ : ChannelServices::.cctor][mdToken=0x6000005][offset 0x0000000C][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack. // [ : ChannelServices::GetPrivateContextsPerfCounters][mdToken= 0x6000002][offset 0x00000002][found Native Int][expected unmanaged pointer] Unexpected type on the stack. - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.PassesIlVerify | Verification.FailsPeVerify).VerifyDiagnostics(); + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics(); } [WorkItem(545026, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545026")] @@ -10350,7 +10350,7 @@ class C "; // PEVerify: // [ : C::.ctor][mdToken=0x6000001][offset 0x0000000A][found Native Int][expected unmanaged pointer] Unexpected type on the stack. - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.PassesIlVerify | Verification.FailsPeVerify).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics( // (4,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); @@ -10369,7 +10369,7 @@ class C "; // PEVerify: // [ : C::.ctor][mdToken=0x6000001][offset 0x00000003][found Native Int][expected unmanaged pointer] Unexpected type on the stack. - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.PassesIlVerify | Verification.FailsPeVerify).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics( // (5,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 0d2d51be37914..1537fe84c5334 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4725,8 +4725,9 @@ public void Bug769741() { var comp = CreateEmptyCompilation("", new[] { TestReferences.SymbolsTests.netModule.x64COFF }, options: TestOptions.DebugDll); // modules not supported in ref emit - // TODO2 ILVerify: Internal.IL.VerifierException : No system module specified - CompileAndVerify(comp, verify: Verification.FailsPeVerify_BadFormat); + // PEVerify: [HRESULT 0x8007000B] - An attempt was made to load a program with an incorrect format. + // ILVerify: Internal.IL.VerifierException : No system module specified + CompileAndVerify(comp, verify: Verification.FailsPeVerify_UnspecifiedError | Verification.FailsIlVerify_UnspecifiedError); Assert.NotSame(comp.Assembly.CorLibrary, comp.Assembly); comp.GetSpecialType(SpecialType.System_Int32); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs index e4919317c64aa..d654c504e2bf6 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs @@ -3073,7 +3073,7 @@ static void M(string s) }"; var comp = CreateEmptyCompilation(text, new[] { reference1 }); - CompileAndVerify(comp, verify: Verification.TypeLoadFailed). + CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). VerifyIL("C.M", @" { // Code size 28 (0x1c) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs index 455394a7b610f..3313599b45ff2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs @@ -2646,7 +2646,7 @@ static void Test1(delegate*[] func) {} [Fact, WorkItem(50096, "https://github.com/dotnet/roslyn/issues/50096")] public void FunctionPointerInference_ExactInferenceThroughArray_RefKindMatch() { - // TODO2 ILVerify: Unexpected type on the stack. ImportCalli not implemented + // ILVerify: Unexpected type on the stack. ImportCalli not implemented var verifier = CompileAndVerify(@" unsafe { @@ -2660,7 +2660,7 @@ static void Test1(delegate*[] func) { System.Console.Write(t); } } -", expectedOutput: "11", options: TestOptions.UnsafeReleaseExe, verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.Passes : Verification.Skipped); +", expectedOutput: "11", options: TestOptions.UnsafeReleaseExe, verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify_UnspecifiedError : Verification.Skipped); verifier.VerifyIL("", @" { diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index f15abd9a31bdb..fe957ebdf3b1d 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -23,65 +23,49 @@ namespace Microsoft.CodeAnalysis.Test.Utilities { + /// + /// Either verification is: + /// - Skipped + /// - Passes + /// - Fails (with breakdown of specific failures) + /// [Flags] public enum Verification { - // TODO2 either it's Skipped, Passes, or we list specific failures - // TODO2 simplify flags? Do we really need a Skipped? Skipped = 0, + Passes = 1 << 2, + Fails = FailsPeVerify_UnspecifiedError | FailsIlVerify_UnspecifiedError, - PassesPeVerify = 1 << 0, - PassesIlVerify = 1 << 1, - FailsPeVerify = 1 << 2, - FailsIlVerify = 1 << 3, - - // ILVerify errors - TypedReference = 1 << 12, - NotImplemented = 1 << 13, - NotVisible = 1 << 14, - UnrecognizedArgDelegate = 1 << 15, - MissingStringType = 1 << 16, - MissingAssembly = 1 << 17, - UnexpectedReadonlyAddressOnStack = 1 << 18, - BadReturnType = 1 << 19, - - // Both - InitOnly = 1 << 20, - - // PEVerify errors - TypeLoadFailed = 1 << 4, - UnexpectedTypeOnStack = 1 << 5, - UnableToResolveToken = 1 << 6, - TypeDevNotNil = 1 << 7, - ClassLayout = 1 << 8, - BadName = 1 << 9, - MissingManifest = 1 << 10, - - Passes = PassesPeVerify | PassesIlVerify, - Fails = FailsPeVerify | FailsIlVerify, + // Don't use these directly + FailsPeVerify = 1 << 3, + FailsIlVerify = 1 << 4, // ILVerify errors - FailsIlVerify_TypedReference = PassesPeVerify | FailsIlVerify | TypedReference, // ILVerify doesn't support TypedReference - FailsIlVerify_NotImplemented = PassesPeVerify | FailsIlVerify | NotImplemented, // ILVerify has some un-implemented cases in EcmaModule.GetType - FailsIlVerify_NotVisible = PassesPeVerify | FailsIlVerify | NotVisible, // ILVerify: Type|Method|Field is not visible. - FailsIlVerify_UnrecognizedArgDelegate = PassesPeVerify | FailsIlVerify | UnrecognizedArgDelegate, // ILVerify: Unrecognized arguments for delegate .ctor. - FailsIlVerify_MissingStringType = PassesPeVerify | FailsIlVerify | MissingStringType, // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - FailsIlVerify_MissingAssembly = PassesPeVerify | FailsIlVerify | MissingAssembly, // ILVerify: Assembly or module not found: ... - FailsIlVerify_UnexpectedReadonlyAddressOnStack = PassesPeVerify | FailsIlVerify | UnexpectedReadonlyAddressOnStack, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } - FailsIlVerify_BadReturnType = PassesPeVerify | FailsIlVerify | BadReturnType, // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + FailsIlVerify_UnspecifiedError = FailsIlVerify | 1 << 5, + FailsIlVerify_TypedReference = FailsIlVerify | 1 << 6, // ILVerify doesn't support TypedReference + FailsIlVerify_NotImplemented = FailsIlVerify | 1 << 7, // ILVerify has some un-implemented cases in EcmaModule.GetType + FailsIlVerify_NotVisible = FailsIlVerify | 1 << 8, // ILVerify: Type|Method|Field is not visible. + FailsIlVerify_UnrecognizedArgDelegate = FailsIlVerify | 1 << 9, // ILVerify: Unrecognized arguments for delegate .ctor. + FailsIlVerify_MissingStringType = FailsIlVerify | 1 << 10, // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... + FailsIlVerify_MissingAssembly = FailsIlVerify | 1 << 11, // ILVerify: Assembly or module not found: ... + FailsIlVerify_UnexpectedReadonlyAddressOnStack = FailsIlVerify | 1 << 12, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } + FailsIlVerify_BadReturnType = FailsIlVerify | 1 << 13, // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. + FailsIlVerify_UnexpectedTypeOnStack = FailsIlVerify | 1 << 14, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } + FailsIlVerify_ImportCalli = FailsIlVerify | 1 << 25, // ILVerify: ImportCalli not implemented // Both - Fails_InitOnly = FailsPeVerify | FailsIlVerify | InitOnly, // Cannot change initonly field outside its .ctor. + Fails_InitOnly = FailsPeVerify | FailsIlVerify | 1 << 15, // Cannot change initonly field outside its .ctor. // PEVerify errors - FailsPeVerify_TypeLoadFailed = FailsPeVerify | PassesIlVerify | TypeLoadFailed, // ILVerify doesn't complain type load failed - FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify | UnexpectedTypeOnStack, // ILVerify doesn't complain about: Unexpected type on the stack. - FailsPeVerify_UnableToResolveToken = FailsPeVerify | PassesIlVerify | UnableToResolveToken, // ILVerify doesn't complain about "unable to resolve token" - FailsPeVerify_TypeDevNotNil = FailsPeVerify | PassesIlVerify | TypeDevNotNil, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. - FailsPeVerify_ClassLayout = FailsPeVerify | PassesIlVerify | ClassLayout, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. - FailsPeVerify_BadName = FailsPeVerify | PassesIlVerify | BadName, // PEVerify complains about: Assembly name contains leading spaces or path or extension. - FailsPeVerify_BadFormat = FailsPeVerify | PassesIlVerify, // PEVerify complains about: An attempt was made to load a program with an incorrect format. - FailsPeVerify_MissingManifest = FailsPeVerify | PassesIlVerify | MissingManifest, // PEVerify complains about: The module was expected to contain an assembly manifest. + FailsPeVerify_UnspecifiedError = FailsIlVerify | 1 << 16, + FailsPeVerify_TypeLoadFailed = FailsPeVerify | 1 << 17, // ILVerify doesn't complain type load failed + FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | 1 << 18, // ILVerify doesn't complain about: Unexpected type on the stack. + FailsPeVerify_UnableToResolveToken = FailsPeVerify | 1 << 19, // ILVerify doesn't complain about "unable to resolve token" + FailsPeVerify_TypeDevNotNil = FailsPeVerify | 1 << 20, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. + FailsPeVerify_ClassLayout = FailsPeVerify | 1 << 21, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. + FailsPeVerify_BadName = FailsPeVerify | 1 << 22, // PEVerify complains about: Assembly name contains leading spaces or path or extension. + FailsPeVerify_BadFormat = FailsPeVerify | 1 << 23, // TODO2 // PEVerify complains about: An attempt was made to load a program with an incorrect format. + FailsPeVerify_MissingManifest = FailsPeVerify | 1 << 24, // PEVerify complains about: The module was expected to contain an assembly manifest. } /// diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 081bb0e34679b..2ef05df63c667 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -148,100 +148,132 @@ public void Verify(Verification verification) emitData.RuntimeData.PeverifyRequested = true; // TODO(https://github.com/dotnet/coreclr/issues/295): Implement peverify - // TODO2 // IL Verify - if ((verification & (Verification.PassesIlVerify | Verification.FailsIlVerify)) != 0) + if (verification == Verification.Skipped) { - var resolver = new Resolver(emitData); - var verifier = new ILVerify.Verifier(resolver); - var mscorlibModules = emitData.AllModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); - if (mscorlibModules.Length == 1) - { - verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); - } - else + return; + } + + var resolver = new Resolver(emitData); + var verifier = new ILVerify.Verifier(resolver); + var mscorlibModules = emitData.AllModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); + if (mscorlibModules.Length == 1) + { + verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); + } + else + { + // auto-detect which module is the "corlib" + foreach (var module in emitData.AllModuleData) { - // auto-detect which module is the "corlib" - foreach (var module in emitData.AllModuleData) + var name = module.SimpleName; + var metadataReader = resolver.Resolve(name).GetMetadataReader(); + if (metadataReader.AssemblyReferences.Count == 0) { - var name = module.SimpleName; - var metadataReader = resolver.Resolve(name).GetMetadataReader(); - if (metadataReader.AssemblyReferences.Count == 0) + try { - try - { - verifier.SetSystemModuleName(new AssemblyName(name)); - } - catch (Exception ex) + verifier.SetSystemModuleName(new AssemblyName(name)); + } + catch (Exception ex) + { + // ILVerify checks that corlib contains certain types + if ((verification & Verification.FailsIlVerify_MissingStringType) == Verification.FailsIlVerify_MissingStringType) { - // ILVerify checks that corlib contains certain types - if ((verification & Verification.MissingStringType) != 0) + if (!ex.Message.Contains("Failed to load type 'System.String' from assembly")) { - if (!ex.Message.Contains("Failed to load type 'System.String' from assembly")) - { - throw new Exception("Expected: Failed to load type 'System.String' from assembly ..."); - } - return; + throw new Exception("Expected: Failed to load type 'System.String' from assembly ..."); } - - throw; + return; } + + throw; } } } + } - var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); - if (result.Count() > 0) - { - string message = printVerificationResult(result); - if ((verification & Verification.PassesIlVerify) != 0) - { - throw new Exception("IL Verify failed unexpectedly: \r\n" + message); - } - if ((verification & Verification.TypedReference) != 0 - && !message.Contains("TypedReference not supported in .NET Core")) - { - throw new Exception("Expected: TypedReference not supported in .NET Core"); - } - if ((verification & Verification.NotImplemented) != 0 - && !message.Contains("The method or operation is not implemented.")) - { - throw new Exception("Expected: The method or operation is not implemented."); - } - if ((verification & Verification.InitOnly) != 0 - && !message.Contains("Cannot change initonly field outside its .ctor.")) - { - throw new Exception("Expected: Cannot change initonly field outside its .ctor."); - } - if ((verification & Verification.NotVisible) != 0 - && !message.Contains(" is not visible.")) - { - throw new Exception("Expected: ... is not visible."); - } - if ((verification & Verification.UnrecognizedArgDelegate) != 0 - && !message.Contains("Unrecognized arguments for delegate .ctor.")) - { - throw new Exception("Expected: Unrecognized arguments for delegate .ctor."); - } - if ((verification & Verification.MissingAssembly) != 0 - && !message.Contains("Assembly or module not found: ")) - { - throw new Exception("Expected: Assembly or module not found: ..."); - } - if ((verification & Verification.UnexpectedReadonlyAddressOnStack) != 0 - && !(message.Contains("Unexpected type on the stack.") - && message.Contains("Found = readonly address of") - && message.Contains("Expected = address of"))) - { - throw new Exception("Expected: Assembly or module not found: ..."); - } - } - else if ((verification & Verification.FailsIlVerify) != 0) + var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); + if (result.Count() == 0) + { + if ((verification & Verification.FailsIlVerify) == 0) { - throw new Exception("IL Verify succeeded unexpectedly"); + return; } + + throw new Exception("IL Verify succeeded unexpectedly"); + } + + string message = printVerificationResult(result); + if ((verification & Verification.FailsIlVerify_TypedReference) == Verification.FailsIlVerify_TypedReference + && message.Contains("TypedReference not supported in .NET Core")) + { + return; + } + + if ((verification & Verification.FailsIlVerify_NotImplemented) == Verification.FailsIlVerify_NotImplemented + && message.Contains("The method or operation is not implemented.")) + { + return; + } + + if ((verification & Verification.Fails_InitOnly) == Verification.Fails_InitOnly + && message.Contains("Cannot change initonly field outside its .ctor.")) + { + return; } + if ((verification & Verification.FailsIlVerify_NotVisible) == Verification.FailsIlVerify_NotVisible + && message.Contains(" is not visible.")) + { + return; + } + + if ((verification & Verification.FailsIlVerify_UnrecognizedArgDelegate) == Verification.FailsIlVerify_UnrecognizedArgDelegate + && message.Contains("Unrecognized arguments for delegate .ctor.")) + { + return; + } + + if ((verification & Verification.FailsIlVerify_MissingAssembly) == Verification.FailsIlVerify_MissingAssembly + && message.Contains("Assembly or module not found: ")) + { + return; + } + + if ((verification & Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack) == Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack + && message.Contains("Unexpected type on the stack.") + && message.Contains("Found = readonly address of") + && message.Contains("Expected = address of")) + { + return; + } + + if ((verification & Verification.FailsIlVerify_BadReturnType) == Verification.FailsIlVerify_BadReturnType + && message.Contains("Return type is ByRef, TypedReference, ArgHandle, or ArgIterator.")) + { + return; + } + + if ((verification & Verification.FailsIlVerify_UnexpectedTypeOnStack) == Verification.FailsIlVerify_UnexpectedTypeOnStack + && message.Contains("Unexpected type on the stack.")) + { + return; + } + + // TODO2 remove? + if ((verification & Verification.FailsIlVerify_ImportCalli) == Verification.FailsIlVerify_ImportCalli + && message.Contains("ImportCalli not implemented")) + { + return; + } + + if ((verification & Verification.FailsIlVerify_UnspecifiedError) == Verification.FailsIlVerify_UnspecifiedError) + { + return; + } + + throw new Exception("IL Verify failed unexpectedly: \r\n" + message); + static string printVerificationResult(IEnumerable result) { return string.Join("\r\n", result.Select(r => r.Message + printErrorArguments(r.ErrorArguments))); diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index 8c19e85754765..415d57bc46828 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -311,58 +311,68 @@ public void Verify(Verification verification) { emitData.RuntimeData.PeverifyRequested = true; emitData.Manager.PeVerifyModules(new[] { emitData.MainModule.FullName }, throwOnError: true); - if ((verification & Verification.FailsPeVerify) != 0) + if ((verification & Verification.FailsPeVerify) == 0) { - throw new Exception("PE Verify succeeded unexpectedly"); + return; } + + throw new Exception("PE Verify succeeded unexpectedly"); } catch (RuntimePeVerifyException ex) { - if ((verification & Verification.PassesPeVerify) != 0) + if ((verification & Verification.FailsPeVerify_TypeLoadFailed) == Verification.FailsPeVerify_TypeLoadFailed + && ex.Message.Contains("Type load failed.")) { - throw new Exception("Verification failed", ex); + return; } - if ((verification & Verification.TypeLoadFailed) != 0 - && !ex.Message.Contains("Type load failed.")) + + if ((verification & Verification.FailsPeVerify_UnexpectedTypeOnStack) == Verification.FailsPeVerify_UnexpectedTypeOnStack + && ex.Message.Contains("Unexpected type on the stack.")) { - throw new Exception("Expected: Type load failed.", ex); + return; } - if ((verification & Verification.UnexpectedTypeOnStack) != 0 - && !ex.Message.Contains("Unexpected type on the stack.")) + + if ((verification & Verification.FailsPeVerify_UnableToResolveToken) == Verification.FailsPeVerify_UnableToResolveToken + && ex.Message.Contains("Unable to resolve token.")) { - throw new Exception("Expected: Unexpected type on the stack.", ex); + return; } - if ((verification & Verification.UnableToResolveToken) != 0 - && !ex.Message.Contains("Unable to resolve token.")) + + if ((verification & Verification.FailsPeVerify_TypeDevNotNil) == Verification.FailsPeVerify_TypeDevNotNil + && ex.Message.Contains("which is not nil.")) { - throw new Exception("Expected: Unable to resolve token.", ex); + return; } - if ((verification & Verification.TypeDevNotNil) != 0 - && !ex.Message.Contains("which is not nil.")) + + if ((verification & Verification.FailsPeVerify_ClassLayout) == Verification.FailsPeVerify_ClassLayout + && ex.Message.Contains("marked AutoLayout.")) { - throw new Exception("Expected: [...] which is not nil.", ex); + return; } - if ((verification & Verification.ClassLayout) != 0 - && !ex.Message.Contains("marked AutoLayout.")) + + if ((verification & Verification.FailsPeVerify_BadName) == Verification.FailsPeVerify_BadName + && ex.Message.Contains("Assembly name contains leading spaces or path or extension.")) { - throw new Exception("Expected: [...] marked AutoLayout.", ex); + return; } - if ((verification & Verification.BadName) != 0 - && !ex.Message.Contains("Assembly name contains leading spaces or path or extension.")) + + if ((verification & Verification.FailsPeVerify_MissingManifest) == Verification.FailsPeVerify_MissingManifest + && ex.Message.Contains("was expected to contain an assembly manifest.")) { - throw new Exception("Expected: Assembly name contains leading spaces or path or extension.", ex); + return; } - if ((verification & Verification.MissingManifest) != 0 - && !ex.Message.Contains("was expected to contain an assembly manifest.")) + + if ((verification & Verification.Fails_InitOnly) == Verification.Fails_InitOnly + && ex.Message.Contains("Cannot change initonly field outside its .ctor.")) { - throw new Exception("Expected: was expected to contain an assembly manifest.", ex); } - if ((verification & Verification.InitOnly) != 0 - && !ex.Message.Contains("Cannot change initonly field outside its .ctor.")) + + if ((verification & Verification.FailsPeVerify_UnspecifiedError) == Verification.FailsPeVerify_UnspecifiedError) { - throw new Exception("Expected: Cannot change initonly field outside its .ctor."); + return; } + throw new Exception("Verification failed", ex); } } From 5a01e5832505b9c37ccf519a8382efee311635ad Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 15:59:58 -0800 Subject: [PATCH 21/51] Ctor --- .../Attributes/AttributeTests_IsByRefLike.cs | 5 +- .../Attributes/AttributeTests_IsUnmanaged.cs | 13 +- .../AttributeTests_ReadOnlyStruct.cs | 5 +- .../Attributes/AttributeTests_RefReadOnly.cs | 17 +- .../Attributes/AttributeTests_Synthesized.cs | 4 +- .../AttributeTests_WellKnownAttributes.cs | 3 +- .../InternalsVisibleToAndStrongNameTests.cs | 3 +- .../Test/Emit/CodeGen/CodeGenIterators.cs | 3 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 2 +- .../Test/Emit/Emit/CompilationEmitTests.cs | 3 +- .../Test/Emit/Emit/EmitMetadataTests.cs | 3 +- src/Compilers/Test/Core/CommonTestBase.cs | 3 +- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 189 +++++++++--------- .../Test/Emit/Emit/CompilationEmitTests.vb | 2 +- 14 files changed, 127 insertions(+), 128 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index acd34b8eeb722..e5b0f6f84c613 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -430,8 +430,7 @@ public class Test { public ref struct S1{} }"; - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); @@ -957,7 +956,7 @@ public ref struct NotTypedReference { } }"; var compilation1 = CreateEmptyCompilation(source1, assemblyName: GetUniqueName()); - CompileAndVerify(compilation1, verify: Verification.FailsPeVerify_TypeLoadFailed, symbolValidator: module => + CompileAndVerify(compilation1, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_ReturnFromCtor, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("System.TypedReference"); AssertReferencedIsByRefLike(type, hasObsolete: false); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs index 107d4301b79f4..dfa203ad6d7d8 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs @@ -255,9 +255,7 @@ public class Test public void M() where T : unmanaged { } } "; - // TODO2 AssemblyTable.NumberOfRows on the MetadataReader is 0 (so IsAssembly is false) - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); @@ -282,8 +280,7 @@ public class Test where T : unmanaged { } "; - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test`1").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); @@ -315,10 +312,9 @@ void N() where T : unmanaged } "; - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify( source: text, - verify: Verification.Fails, + verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => @@ -345,10 +341,9 @@ public class IsUnmanagedAttribute : System.Attribute { } public delegate void D() where T : unmanaged; "; - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify( source: text, - verify: Verification.Fails, + verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs index 98818228ca92b..75d4421cb78e4 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs @@ -427,8 +427,9 @@ public class Test public readonly struct S1{} }"; - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + // PEVerify: The module was expected to contain an assembly manifest. + // ILVerify: The format of a DLL or executable being loaded is invalid + CompileAndVerify(code, verify: Verification.Skipped, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); Assert.True(type.IsReadOnly); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs index 7a8cfd717a0ff..e26fbda3cf70c 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs @@ -1152,15 +1152,14 @@ public class Test { public void M(in int x) { } }"; - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => - { - AssertNoIsReadOnlyAttributeExists(module.ContainingAssembly); - - var parameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").GetParameters().Single(); - Assert.Equal(RefKind.In, parameter.RefKind); - Assert.Empty(parameter.GetAttributes()); - }); + CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + { + AssertNoIsReadOnlyAttributeExists(module.ContainingAssembly); + + var parameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").GetParameters().Single(); + Assert.Equal(RefKind.In, parameter.RefKind); + Assert.Empty(parameter.GetAttributes()); + }); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index 5363fcb84ed3e..593b3794b4c36 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -955,9 +955,9 @@ public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(Ou else { // ILVerify: Failed to load type 'System.String' from assembly - // TODO2 ILVerify: Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid + // ILVerify: The format of a DLL or executable being loaded is invalid var verify = outputKind.IsNetModule() - ? Verification.FailsPeVerify_MissingManifest + ? Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage : Verification.FailsIlVerify_MissingStringType; CompileAndVerify(compilation, verify: verify, symbolValidator: module => diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs index 08a5a780a25a8..65e25fda9fd51 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs @@ -12564,8 +12564,7 @@ void M() } "; - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - var comp = CompileAndVerify(source, options: TestOptions.DebugModule.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_MissingManifest); + var comp = CompileAndVerify(source, options: TestOptions.DebugModule.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage); Assert.False(comp.HasLocalsInit("C.M")); } diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index 04c74c6f3972f..a55c927c11e25 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2671,8 +2671,7 @@ public A GetA() references: new[] { new CSharpCompilationReference(ca) }, parseOptions: parseOptions); - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - CompileAndVerify(cb, verify: Verification.Fails).Diagnostics.Verify(); + CompileAndVerify(cb, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage).Diagnostics.Verify(); } [WorkItem(1072350, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1072350")] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs index 15b0342d4aa80..5e5e1d85686fa 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs @@ -2387,8 +2387,7 @@ public System.Collections.IEnumerable SomeNumbers() }"; // The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available. var compilation = CreateEmptyCompilation(new[] { Parse(source), Parse(corlib) }); - // TODO2 ILVerify: Return from .ctor when this is uninitialized. Unexpected type on the stack. - var verifier = CompileAndVerify(compilation, verify: Verification.FailsPeVerify_TypeLoadFailed); + var verifier = CompileAndVerify(compilation, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_ReturnFromCtor); verifier.VerifyDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1)); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index bbc2925eb38b7..657f387c33c24 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -5288,7 +5288,7 @@ .maxstack 2 compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); // expect the same IL in the compat case since direct references are required and must be emitted with "readonly.", even though unverifiable - compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); + compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack | Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 1537fe84c5334..87ed5fbde4957 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4309,8 +4309,7 @@ public void EmitNetModuleWithReferencedNetModule() string source2 = @"public class B: A {}"; var comp = CreateCompilation(source1, options: TestOptions.ReleaseModule); var metadataRef = ModuleMetadata.CreateFromStream(comp.EmitToStream()).GetReference(); - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid - CompileAndVerify(source2, references: new[] { metadataRef }, options: TestOptions.ReleaseModule, verify: Verification.Fails); + CompileAndVerify(source2, references: new[] { metadataRef }, options: TestOptions.ReleaseModule, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage); } [ConditionalFact(typeof(WindowsOnly), Reason = "https://github.com/dotnet/roslyn/issues/30169")] diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs index ae62c117a554d..f0e5d2b710714 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs @@ -224,10 +224,9 @@ public class Test : Class2 [Fact()] public void Bug687434() { - // TODO2 Internal.TypeSystem.TypeSystemException+BadImageFormatException : The format of a DLL or executable being loaded is invalid CompileAndVerify( "public class C { }", - verify: Verification.Fails, + verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, options: TestOptions.DebugDll.WithOutputKind(OutputKind.NetModule)); } diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index fe957ebdf3b1d..c4f97ed02ffb1 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -51,7 +51,8 @@ public enum Verification FailsIlVerify_UnexpectedReadonlyAddressOnStack = FailsIlVerify | 1 << 12, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } FailsIlVerify_BadReturnType = FailsIlVerify | 1 << 13, // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. FailsIlVerify_UnexpectedTypeOnStack = FailsIlVerify | 1 << 14, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } - FailsIlVerify_ImportCalli = FailsIlVerify | 1 << 25, // ILVerify: ImportCalli not implemented + FailsIlVerify_ReturnFromCtor = FailsIlVerify | 1 << 25, // ILVerify: ImportCalli not implemented + FailsIlVerify_BadImage = FailsIlVerify | 1 << 26, // ILVerify: The format of a DLL or executable being loaded is invalid // Both Fails_InitOnly = FailsPeVerify | FailsIlVerify | 1 << 15, // Cannot change initonly field outside its .ctor. diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 2ef05df63c667..879970078ce5c 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -154,125 +154,134 @@ public void Verify(Verification verification) return; } - var resolver = new Resolver(emitData); - var verifier = new ILVerify.Verifier(resolver); - var mscorlibModules = emitData.AllModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); - if (mscorlibModules.Length == 1) + try { - verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); - } - else - { - // auto-detect which module is the "corlib" - foreach (var module in emitData.AllModuleData) + var resolver = new Resolver(emitData); + var verifier = new ILVerify.Verifier(resolver); + var mscorlibModules = emitData.AllModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); + if (mscorlibModules.Length == 1) + { + verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); + } + else { - var name = module.SimpleName; - var metadataReader = resolver.Resolve(name).GetMetadataReader(); - if (metadataReader.AssemblyReferences.Count == 0) + // auto-detect which module is the "corlib" + foreach (var module in emitData.AllModuleData) { - try + var name = module.SimpleName; + var metadataReader = resolver.Resolve(name).GetMetadataReader(); + if (metadataReader.AssemblyReferences.Count == 0) { - verifier.SetSystemModuleName(new AssemblyName(name)); - } - catch (Exception ex) - { - // ILVerify checks that corlib contains certain types - if ((verification & Verification.FailsIlVerify_MissingStringType) == Verification.FailsIlVerify_MissingStringType) + try { - if (!ex.Message.Contains("Failed to load type 'System.String' from assembly")) + verifier.SetSystemModuleName(new AssemblyName(name)); + } + catch (Exception ex) + { + // ILVerify checks that corlib contains certain types + if ((verification & Verification.FailsIlVerify_MissingStringType) == Verification.FailsIlVerify_MissingStringType + && ex.Message.Contains("Failed to load type 'System.String' from assembly")) { - throw new Exception("Expected: Failed to load type 'System.String' from assembly ..."); + return; } - return; - } - throw; + throw; + } } } } - } - var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); - if (result.Count() == 0) - { - if ((verification & Verification.FailsIlVerify) == 0) + var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); + if (result.Count() == 0) + { + if ((verification & Verification.FailsIlVerify) == 0) + { + return; + } + + throw new Exception("IL Verify succeeded unexpectedly"); + } + + string message = printVerificationResult(result); + if ((verification & Verification.FailsIlVerify_TypedReference) == Verification.FailsIlVerify_TypedReference + && message.Contains("TypedReference not supported in .NET Core")) { return; } - throw new Exception("IL Verify succeeded unexpectedly"); - } + if ((verification & Verification.FailsIlVerify_NotImplemented) == Verification.FailsIlVerify_NotImplemented + && message.Contains("The method or operation is not implemented.")) + { + return; + } - string message = printVerificationResult(result); - if ((verification & Verification.FailsIlVerify_TypedReference) == Verification.FailsIlVerify_TypedReference - && message.Contains("TypedReference not supported in .NET Core")) - { - return; - } + if ((verification & Verification.Fails_InitOnly) == Verification.Fails_InitOnly + && message.Contains("Cannot change initonly field outside its .ctor.")) + { + return; + } - if ((verification & Verification.FailsIlVerify_NotImplemented) == Verification.FailsIlVerify_NotImplemented - && message.Contains("The method or operation is not implemented.")) - { - return; - } + if ((verification & Verification.FailsIlVerify_NotVisible) == Verification.FailsIlVerify_NotVisible + && message.Contains(" is not visible.")) + { + return; + } - if ((verification & Verification.Fails_InitOnly) == Verification.Fails_InitOnly - && message.Contains("Cannot change initonly field outside its .ctor.")) - { - return; - } + if ((verification & Verification.FailsIlVerify_UnrecognizedArgDelegate) == Verification.FailsIlVerify_UnrecognizedArgDelegate + && message.Contains("Unrecognized arguments for delegate .ctor.")) + { + return; + } - if ((verification & Verification.FailsIlVerify_NotVisible) == Verification.FailsIlVerify_NotVisible - && message.Contains(" is not visible.")) - { - return; - } + if ((verification & Verification.FailsIlVerify_MissingAssembly) == Verification.FailsIlVerify_MissingAssembly + && message.Contains("Assembly or module not found: ")) + { + return; + } - if ((verification & Verification.FailsIlVerify_UnrecognizedArgDelegate) == Verification.FailsIlVerify_UnrecognizedArgDelegate - && message.Contains("Unrecognized arguments for delegate .ctor.")) - { - return; - } + if ((verification & Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack) == Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack + && message.Contains("Unexpected type on the stack.") + && message.Contains("Found = readonly address of") + && message.Contains("Expected = address of")) + { + return; + } - if ((verification & Verification.FailsIlVerify_MissingAssembly) == Verification.FailsIlVerify_MissingAssembly - && message.Contains("Assembly or module not found: ")) - { - return; - } + if ((verification & Verification.FailsIlVerify_BadReturnType) == Verification.FailsIlVerify_BadReturnType + && message.Contains("Return type is ByRef, TypedReference, ArgHandle, or ArgIterator.")) + { + return; + } - if ((verification & Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack) == Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack - && message.Contains("Unexpected type on the stack.") - && message.Contains("Found = readonly address of") - && message.Contains("Expected = address of")) - { - return; - } + if ((verification & Verification.FailsIlVerify_UnexpectedTypeOnStack) == Verification.FailsIlVerify_UnexpectedTypeOnStack + && message.Contains("Unexpected type on the stack.")) + { + return; + } - if ((verification & Verification.FailsIlVerify_BadReturnType) == Verification.FailsIlVerify_BadReturnType - && message.Contains("Return type is ByRef, TypedReference, ArgHandle, or ArgIterator.")) - { - return; - } + if ((verification & Verification.FailsIlVerify_ReturnFromCtor) == Verification.FailsIlVerify_ReturnFromCtor + && message.Contains("Return from .ctor when this is uninitialized.")) + { + return; + } - if ((verification & Verification.FailsIlVerify_UnexpectedTypeOnStack) == Verification.FailsIlVerify_UnexpectedTypeOnStack - && message.Contains("Unexpected type on the stack.")) - { - return; - } + if ((verification & Verification.FailsIlVerify_UnspecifiedError) == Verification.FailsIlVerify_UnspecifiedError) + { + return; + } - // TODO2 remove? - if ((verification & Verification.FailsIlVerify_ImportCalli) == Verification.FailsIlVerify_ImportCalli - && message.Contains("ImportCalli not implemented")) - { - return; + throw new Exception("IL Verify failed unexpectedly: \r\n" + message); } - - if ((verification & Verification.FailsIlVerify_UnspecifiedError) == Verification.FailsIlVerify_UnspecifiedError) + catch (Exception ex) { - return; - } + if ((verification & Verification.FailsIlVerify_BadImage) == Verification.FailsIlVerify_BadImage + && ex.Message.Contains("The format of a DLL or executable being loaded is invalid")) + { + return; + } - throw new Exception("IL Verify failed unexpectedly: \r\n" + message); + throw; + } static string printVerificationResult(IEnumerable result) { diff --git a/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb b/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb index bf050def0c3cf..43e9e28ed9ef6 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb @@ -3560,7 +3560,7 @@ End Class Dim comp = CreateCompilationWithMscorlib40(source1, OutputKind.NetModule) Dim metadataRef = comp.EmitToImageReference() - CompileAndVerify(source2, references:={metadataRef}, options:=TestOptions.ReleaseModule, verify:=Verification.Fails) + CompileAndVerify(source2, references:={metadataRef}, options:=TestOptions.ReleaseModule, verify:=Verification.FailsPeVerify_MissingManifest Or Verification.FailsIlVerify_BadImage) End Sub From ae83e168e6a7f90b64d126f0ef0ecb2ac315ed1a Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 16:10:25 -0800 Subject: [PATCH 22/51] more --- .../CSharp/Test/Emit/Emit/CompilationEmitTests.cs | 2 +- .../Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 87ed5fbde4957..d0352fc46a280 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4726,7 +4726,7 @@ public void Bug769741() // modules not supported in ref emit // PEVerify: [HRESULT 0x8007000B] - An attempt was made to load a program with an incorrect format. // ILVerify: Internal.IL.VerifierException : No system module specified - CompileAndVerify(comp, verify: Verification.FailsPeVerify_UnspecifiedError | Verification.FailsIlVerify_UnspecifiedError); + CompileAndVerify(comp, verify: Verification.Fails); Assert.NotSame(comp.Assembly.CorLibrary, comp.Assembly); comp.GetSpecialType(SpecialType.System_Int32); } diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 879970078ce5c..ceb5d818f9ae8 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -119,10 +119,6 @@ internal Resolver(EmitData emitData) foreach (var module in emitData.AllModuleData) { string name = module.FullName; - - //var image = name == "mscorlib" - // ? ImmutableArray.Empty // TODO2 TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() - // : module.Image; var image = module.Image; // TODO2 figure out why we need both the simple name and full name @@ -280,6 +276,11 @@ public void Verify(Verification verification) return; } + if ((verification & Verification.FailsIlVerify_UnspecifiedError) == Verification.FailsIlVerify_UnspecifiedError) + { + return; + } + throw; } From 9b1260cebb6c1e1c9cbab33c6a219901a455d1e3 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 16:14:33 -0800 Subject: [PATCH 23/51] more --- src/Compilers/Test/Core/CommonTestBase.cs | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index c4f97ed02ffb1..74a94b37a4d60 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -51,22 +51,22 @@ public enum Verification FailsIlVerify_UnexpectedReadonlyAddressOnStack = FailsIlVerify | 1 << 12, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } FailsIlVerify_BadReturnType = FailsIlVerify | 1 << 13, // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. FailsIlVerify_UnexpectedTypeOnStack = FailsIlVerify | 1 << 14, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } - FailsIlVerify_ReturnFromCtor = FailsIlVerify | 1 << 25, // ILVerify: ImportCalli not implemented - FailsIlVerify_BadImage = FailsIlVerify | 1 << 26, // ILVerify: The format of a DLL or executable being loaded is invalid + FailsIlVerify_ReturnFromCtor = FailsIlVerify | 1 << 15, // ILVerify: ImportCalli not implemented + FailsIlVerify_BadImage = FailsIlVerify | 1 << 16, // ILVerify: The format of a DLL or executable being loaded is invalid // Both - Fails_InitOnly = FailsPeVerify | FailsIlVerify | 1 << 15, // Cannot change initonly field outside its .ctor. + Fails_InitOnly = FailsPeVerify | FailsIlVerify | 1 << 17, // Cannot change initonly field outside its .ctor. // PEVerify errors - FailsPeVerify_UnspecifiedError = FailsIlVerify | 1 << 16, - FailsPeVerify_TypeLoadFailed = FailsPeVerify | 1 << 17, // ILVerify doesn't complain type load failed - FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | 1 << 18, // ILVerify doesn't complain about: Unexpected type on the stack. - FailsPeVerify_UnableToResolveToken = FailsPeVerify | 1 << 19, // ILVerify doesn't complain about "unable to resolve token" - FailsPeVerify_TypeDevNotNil = FailsPeVerify | 1 << 20, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. - FailsPeVerify_ClassLayout = FailsPeVerify | 1 << 21, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. - FailsPeVerify_BadName = FailsPeVerify | 1 << 22, // PEVerify complains about: Assembly name contains leading spaces or path or extension. - FailsPeVerify_BadFormat = FailsPeVerify | 1 << 23, // TODO2 // PEVerify complains about: An attempt was made to load a program with an incorrect format. - FailsPeVerify_MissingManifest = FailsPeVerify | 1 << 24, // PEVerify complains about: The module was expected to contain an assembly manifest. + FailsPeVerify_UnspecifiedError = FailsIlVerify | 1 << 18, + FailsPeVerify_TypeLoadFailed = FailsPeVerify | 1 << 19, // ILVerify doesn't complain type load failed + FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | 1 << 20, // ILVerify doesn't complain about: Unexpected type on the stack. + FailsPeVerify_UnableToResolveToken = FailsPeVerify | 1 << 21, // ILVerify doesn't complain about "unable to resolve token" + FailsPeVerify_TypeDevNotNil = FailsPeVerify | 1 << 22, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. + FailsPeVerify_ClassLayout = FailsPeVerify | 1 << 23, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. + FailsPeVerify_BadName = FailsPeVerify | 1 << 24, // PEVerify complains about: Assembly name contains leading spaces or path or extension. + FailsPeVerify_BadFormat = FailsPeVerify | 1 << 25, // TODO2 // PEVerify complains about: An attempt was made to load a program with an incorrect format. + FailsPeVerify_MissingManifest = FailsPeVerify | 1 << 26, // PEVerify complains about: The module was expected to contain an assembly manifest. } /// From ec5417725fe709504c86a19ee71aae75bc891bf1 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 1 Jan 2022 23:23:26 -0800 Subject: [PATCH 24/51] tweak --- .../Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index 415d57bc46828..cd34fd84cfea6 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -365,6 +365,7 @@ public void Verify(Verification verification) if ((verification & Verification.Fails_InitOnly) == Verification.Fails_InitOnly && ex.Message.Contains("Cannot change initonly field outside its .ctor.")) { + return; } if ((verification & Verification.FailsPeVerify_UnspecifiedError) == Verification.FailsPeVerify_UnspecifiedError) From 99e0f0a9594c00314752fe581ea572074e6e5304 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sun, 2 Jan 2022 00:23:50 -0800 Subject: [PATCH 25/51] VB --- .../VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb | 6 ++++++ .../VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb | 4 +++- .../VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb | 6 ++++-- .../VisualBasic/Test/Emit/CodeGen/CodeGenTryCatchThrow.vb | 3 +++ .../Emit/Emit/EditAndContinue/AssemblyReferencesTests.vb | 2 ++ src/Compilers/VisualBasic/Test/Emit/Emit/EmitMetadata.vb | 6 ++++-- src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb | 2 ++ src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb | 1 + .../Test/Semantic/Compilation/CompilationAPITests.vb | 3 ++- .../Test/Semantic/Semantics/ConditionalAccessTests.vb | 3 ++- .../Test/Semantic/Semantics/IReadOnlyListAndCollection.vb | 7 +++++-- 11 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb b/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb index 5085180d99d03..ba00e3c160777 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb @@ -764,8 +764,10 @@ end class ]]> , options:=TestOptions.ReleaseDll, references:={hash_module}) + ' ILVerify: Assembly or module not found: hash_module CompileAndVerify(compilation, manifestResources:=hash_resources, + verify:=Verification.FailsIlVerify_MissingAssembly, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -796,6 +798,7 @@ end class CompileAndVerify(compilation, manifestResources:=hash_resources, + verify:=Verification.FailsIlVerify_MissingAssembly, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -826,6 +829,7 @@ end class CompileAndVerify(compilation, manifestResources:=hash_resources, + verify:=Verification.FailsIlVerify_MissingAssembly, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -856,6 +860,7 @@ end class CompileAndVerify(compilation, manifestResources:=hash_resources, + verify:=Verification.FailsIlVerify_MissingAssembly, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -994,6 +999,7 @@ end class , options:=TestOptions.ReleaseDll, references:={hash_module_Comp.EmitToImageReference()}) CompileAndVerify(compilation, + verify:=Verification.FailsIlVerify_MissingAssembly, validator:=Sub(peAssembly) Dim metadataReader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = metadataReader.GetAssemblyDefinition() diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb index 088a1e40c2787..62bb09bd16e88 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb @@ -2,6 +2,7 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports Microsoft.CodeAnalysis.Test.Utilities Imports Roslyn.Test.Utilities Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests @@ -2399,6 +2400,7 @@ End Class Public Sub NoObjectCopyForGetCurrent() + ' ILVerify: Unexpected type on the stack. { Offset = 25, Found = readonly address of '[...]C2+S1', Expected = address of '[...]C2+S1' } Dim TEMP = CompileAndVerify( @@ -2435,7 +2437,7 @@ End Class , expectedOutput:=).VerifyIL("C2.DoStuff", , verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack).VerifyIL("C2.DoStuff", Public Sub Bug776642a() + ' ILVerify: Unexpected type on the stack. { Offset = 16, Found = readonly address of '[...]OuterStruct', Expected = address of '[...]OuterStruct' } CompileAndVerify( @@ -51,7 +52,7 @@ Structure OuterStruct Public z As DoubleAndStruct End Structure -). +, verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack). VerifyIL("Program.M", Public Sub Bug776642a_ref() + ' ILVerify: Unexpected type on the stack. { Offset = 30, Found = readonly address of '[...]OuterStruct', Expected = address of '[...]OuterStruct' } CompileAndVerify( @@ -164,7 +166,7 @@ Structure OuterStruct Public z As DoubleAndStruct End Structure -). +, verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack). VerifyIL("Program.M", Public Sub GotoOutOfCatch() + ' ILVerify: Leave into try block. { Offset = 55 } CompileAndVerify( @@ -119,6 +121,7 @@ L2: End Module , +verify:=Verification.Passes, ' TODO2 expectedOutput:="TryGoToCatchFinally"). VerifyIL("EmitTest.Main", + ' TODO2 + ' ILVerify: Leave into try block. { Offset = 75 } Dim v = CompileAndVerify(CreateCompilationWithMscorlib40AndVBRuntime(source, TestOptions.DebugExe)) v.VerifyIL("M1.Main", " diff --git a/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb b/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb index f17c093a1af79..d2bbd49cced0c 100644 --- a/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb @@ -2915,6 +2915,7 @@ End Module Public Sub ValueExtensionProperty() + ' ILVerify: Unexpected type on the stack. { Offset = 117, Found = ref '[mscorlib]System.Collections.Generic.IEnumerable`1', Expected = ref '[mscorlib]System.Collections.Generic.IEnumerable`1' } Dim compilation = CompileAndVerify( , references:={netModule1.EmitToImageReference(), netModule2.EmitToImageReference()}) assembly.VerifyDiagnostics() - CompileAndVerify(assembly) + ' ILVerify: Assembly or module not found: missing2 + CompileAndVerify(assembly, verify:=Verification.FailsIlVerify_MissingAssembly) End Sub diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb index 813cc68418b46..2cc703489d531 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb @@ -3998,6 +3998,7 @@ BC41999: Implicit conversion from 'I1' to 'C1' in copying the value of 'ByRef' p ~ ]]>) + ' ILVerify: Unexpected type on the stack. { Offset = 39, Found = readonly address of '[...]S1', Expected = address of '[...]S1' } Dim verifier = CompileAndVerify(compilation, expectedOutput:= ) +]]>, verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack) End Sub diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb index 98d104745cea5..d58c8051a7f97 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb @@ -2,6 +2,7 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -115,6 +116,7 @@ End Module ) + ' ILVerify: Unexpected type on the stack. { Offset = 232, Found = ref 'int32[][]', Expected = ref '[mscorlib]System.Collections.Generic.IList`1>' } CompileAndVerify(compilation, ) +]]>, verify:=Verification.FailsIlVerify_UnexpectedTypeOnStack) End Sub @@ -330,6 +332,7 @@ End Module ) + ' ILVerify: Unexpected type on the stack. { Offset = 232, Found = ref 'int32[][]', Expected = ref '[mscorlib]System.Collections.Generic.IList`1>' } CompileAndVerify(compilation, ) +]]>, verify:=Verification.FailsIlVerify_UnexpectedTypeOnStack) End Sub From b2fc7c73eed587d5a8c85cd7e83f57cf15ad1b51 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Mon, 3 Jan 2022 09:18:33 -0800 Subject: [PATCH 26/51] Conditional package reference --- .../Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj index 7027dcf3bf103..3eda13903b3b0 100644 --- a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj +++ b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj @@ -106,7 +106,7 @@ - + From ebacf4fd886ea233645ae2f4dc0e4275aca1b256 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Wed, 5 Jan 2022 11:13:19 -0800 Subject: [PATCH 27/51] Remove tracking of specific failures --- .../Attributes/AttributeTests_Assembly.cs | 12 +-- .../Emit/Attributes/AttributeTests_Dynamic.cs | 4 +- .../Attributes/AttributeTests_IsByRefLike.cs | 4 +- .../Attributes/AttributeTests_IsUnmanaged.cs | 8 +- .../Attributes/AttributeTests_RefReadOnly.cs | 2 +- .../Attributes/AttributeTests_StructLayout.cs | 6 +- .../Attributes/AttributeTests_Synthesized.cs | 4 +- .../AttributeTests_WellKnownAttributes.cs | 6 +- .../InternalsVisibleToAndStrongNameTests.cs | 2 +- .../Emit/CodeGen/CodeGenAwaitForeachTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenDynamicTests.cs | 2 +- .../Emit/CodeGen/CodeGenExprLambdaTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenForEachTests.cs | 18 ++-- .../Emit/CodeGen/CodeGenIncrementTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenIterators.cs | 2 +- .../Test/Emit/CodeGen/CodeGenMscorlib.cs | 4 +- .../CodeGen/CodeGenOverridingAndHiding.cs | 2 +- .../Test/Emit/CodeGen/CodeGenScriptTests.cs | 2 +- .../CodeGenShortCircuitOperatorTests.cs | 2 +- .../CodeGenStackAllocInitializerTests.cs | 2 +- .../Emit/CodeGen/CodeGenStructsAndEnum.cs | 6 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 16 ++-- .../Test/Emit/CodeGen/DestructorTests.cs | 2 +- .../CSharp/Test/Emit/CodeGen/SwitchTests.cs | 2 +- .../CSharp/Test/Emit/CodeGen/UnsafeTests.cs | 20 ++-- .../Test/Emit/Emit/CompilationEmitTests.cs | 4 +- .../EditAndContinueStateMachineTests.cs | 8 +- .../Test/Emit/Emit/EmitCustomModifiers.cs | 4 +- .../Test/Emit/Emit/EmitMetadataTests.cs | 6 +- .../CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs | 12 +-- .../Test/Semantic/Semantics/ArglistTests.cs | 10 +- .../Semantic/Semantics/BetterCandidates.cs | 2 +- .../BindingAsyncTasklikeMoreTests.cs | 4 +- .../Semantic/Semantics/DelegateTypeTests.cs | 8 +- .../Test/Semantic/Semantics/DynamicTests.cs | 4 +- .../Test/Semantic/Semantics/ForEachTests.cs | 2 +- .../Semantics/FunctionPointerTests.cs | 2 +- .../Semantic/Semantics/InitOnlyMemberTests.cs | 18 ++-- .../Semantic/Semantics/InterpolationTests.cs | 4 +- .../Semantics/NamedAndOptionalTests.cs | 2 +- .../Semantics/NullableReferenceTypesTests.cs | 4 +- .../Semantics/OverloadResolutionTests.cs | 4 +- .../Semantics/PatternMatchingTests.cs | 4 +- .../Semantics/PatternMatchingTests3.cs | 2 +- .../PatternMatchingTests_ListPatterns.cs | 42 ++++----- .../Semantics/SpanStackSafetyTests.cs | 2 +- .../Semantics/TargetTypedDefaultTests.cs | 2 +- .../Symbol/Compilation/CompilationAPITests.cs | 2 +- .../Symbol/Compilation/UsedAssembliesTests.cs | 6 +- .../DefaultInterfaceImplementationTests.cs | 42 +++++---- .../Symbol/Symbols/ExtensionMethodTests.cs | 14 +-- .../Test/Symbol/Symbols/SymbolErrorTests.cs | 2 +- src/Compilers/Test/Core/CommonTestBase.cs | 45 +-------- ...crosoft.CodeAnalysis.Test.Utilities.csproj | 2 +- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 93 +------------------ .../Desktop/DesktopRuntimeEnvironment.cs | 50 +--------- .../Emit/Attributes/AssemblyAttributes.vb | 10 +- .../Test/Emit/CodeGen/CodeGenForeach.vb | 2 +- .../Test/Emit/CodeGen/CodeGenTests.vb | 4 +- .../Test/Emit/Emit/CompilationEmitTests.vb | 2 +- .../Test/Emit/Emit/EmitMetadata.vb | 4 +- .../Compilation/CompilationAPITests.vb | 2 +- .../Semantics/ConditionalAccessTests.vb | 2 +- .../Semantics/IReadOnlyListAndCollection.vb | 4 +- 64 files changed, 203 insertions(+), 367 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 5e32eb5544a48..4d07412d081fc 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -300,7 +300,7 @@ public void MismatchedSurrogateInAssemblyCultureAttribute() // PEVerify: // Warning: Invalid locale string. - CompileAndVerify(comp, verify: Verification.FailsPeVerify_UnspecifiedError, symbolValidator: m => + CompileAndVerify(comp, verify: Verification.FailsPeVerify, symbolValidator: m => { var utf8 = new System.Text.UTF8Encoding(false, false); Assert.Equal(utf8.GetString(utf8.GetBytes("\uD800")), m.ContainingAssembly.Identity.CultureName); @@ -545,7 +545,7 @@ void M(Test x) {} // ILVerify: Assembly or module not found: hash_module CompileAndVerify(compilation, - verify: Verification.FailsIlVerify_MissingAssembly, + verify: Verification.FailsIlVerify, manifestResources: hash_resources, validator: (peAssembly) => { @@ -576,7 +576,7 @@ void M(Test x) {} // ILVerify: Assembly or module not found: hash_module CompileAndVerify(compilation, - verify: Verification.FailsIlVerify_MissingAssembly, + verify: Verification.FailsIlVerify, manifestResources: hash_resources, validator: (peAssembly) => { @@ -606,7 +606,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.FailsIlVerify_MissingAssembly, + verify: Verification.FailsIlVerify, manifestResources: hash_resources, validator: (peAssembly) => { @@ -636,7 +636,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module }); CompileAndVerify(compilation, - verify: Verification.FailsIlVerify_MissingAssembly, + verify: Verification.FailsIlVerify, manifestResources: hash_resources, validator: (peAssembly) => { @@ -767,7 +767,7 @@ void M(Test x) {} ", options: TestOptions.ReleaseDll, references: new[] { hash_module_Comp.EmitToImageReference() }); CompileAndVerify(compilation, - verify: Verification.FailsIlVerify_MissingAssembly, + verify: Verification.FailsIlVerify, validator: (peAssembly) => { var peReader = peAssembly.ManifestModule.GetMetadataReader(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index 0fd56d5a3d3af..f77709947667b 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1157,7 +1157,7 @@ static void Main() // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. // ILVerify: Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType); + CompileAndVerify(comp, verify: Verification.Fails); } [Fact] @@ -1193,7 +1193,7 @@ static void Main() // Make sure we emit without errors when System.Boolean is missing. // PEVerify: Type load failed. // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType); + CompileAndVerify(comp, verify: Verification.Fails); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index e5b0f6f84c613..7ed608705a040 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -430,7 +430,7 @@ public class Test { public ref struct S1{} }"; - CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); @@ -956,7 +956,7 @@ public ref struct NotTypedReference { } }"; var compilation1 = CreateEmptyCompilation(source1, assemblyName: GetUniqueName()); - CompileAndVerify(compilation1, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_ReturnFromCtor, symbolValidator: module => + CompileAndVerify(compilation1, verify: Verification.Fails, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("System.TypedReference"); AssertReferencedIsByRefLike(type, hasObsolete: false); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs index dfa203ad6d7d8..34ffeecc7e81f 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs @@ -255,7 +255,7 @@ public class Test public void M() where T : unmanaged { } } "; - CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(text, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); @@ -280,7 +280,7 @@ public class Test where T : unmanaged { } "; - CompileAndVerify(text, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(text, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test`1").TypeParameters.Single(); Assert.True(typeParameter.HasValueTypeConstraint); @@ -314,7 +314,7 @@ void N() where T : unmanaged CompileAndVerify( source: text, - verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, + verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => @@ -343,7 +343,7 @@ public class IsUnmanagedAttribute : System.Attribute { } CompileAndVerify( source: text, - verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, + verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs index e26fbda3cf70c..0ac1eb31cb9a9 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs @@ -1152,7 +1152,7 @@ public class Test { public void M(in int x) { } }"; - CompileAndVerify(code, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { AssertNoIsReadOnlyAttributeExists(module.ContainingAssembly); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs index ac62d8a61f384..8846a3dc301dc 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs @@ -215,10 +215,10 @@ class Structs }; CompileAndVerify(verifiable, assemblyValidator: validator); - CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.FailsPeVerify_ClassLayout); + CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.FailsPeVerify); // CLR limitation on type size, not a RefEmit bug: - CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.FailsPeVerify_ClassLayout); + CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.FailsPeVerify); } [Fact] @@ -336,7 +336,7 @@ public class C : B } "; // type C can't be loaded - CompileAndVerify(source, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(source, verify: Verification.FailsPeVerify); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index 593b3794b4c36..2e4857c663560 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -957,8 +957,8 @@ public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(Ou // ILVerify: Failed to load type 'System.String' from assembly // ILVerify: The format of a DLL or executable being loaded is invalid var verify = outputKind.IsNetModule() - ? Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage - : Verification.FailsIlVerify_MissingStringType; + ? Verification.Fails + : Verification.FailsIlVerify; CompileAndVerify(compilation, verify: verify, symbolValidator: module => { diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs index 65e25fda9fd51..f4c00bd72ff42 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs @@ -3606,7 +3606,7 @@ public static int Main () // the resulting code does not need to verify // This is consistent with Dev10 behavior - CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.FailsPeVerify_UnableToResolveToken, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); + CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.FailsPeVerify, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); } [Fact, WorkItem(544507, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544507")] @@ -5553,7 +5553,7 @@ public static void Main() {} // Dev10 Runtime Exception: // Unhandled Exception: System.TypeLoadException: Windows Runtime types can only be declared in Windows Runtime assemblies. - var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify_TypeLoadFailed, targetFramework: TargetFramework.Mscorlib40); + var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify, targetFramework: TargetFramework.Mscorlib40); } #endregion @@ -12564,7 +12564,7 @@ void M() } "; - var comp = CompileAndVerify(source, options: TestOptions.DebugModule.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage); + var comp = CompileAndVerify(source, options: TestOptions.DebugModule.WithAllowUnsafe(true), verify: Verification.Fails); Assert.False(comp.HasLocalsInit("C.M")); } diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index a55c927c11e25..b25ca9823064a 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2671,7 +2671,7 @@ public A GetA() references: new[] { new CSharpCompilationReference(ca) }, parseOptions: parseOptions); - CompileAndVerify(cb, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage).Diagnostics.Verify(); + CompileAndVerify(cb, verify: Verification.Fails).Diagnostics.Verify(); } [WorkItem(1072350, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1072350")] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs index 4819857ca19f2..8a90c4e6427d5 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitForeachTests.cs @@ -6161,7 +6161,7 @@ public static async IAsyncEnumerator GetAsyncEnumerator(this Range range) options: TestOptions.DebugExe, parseOptions: TestOptions.Regular9); comp.VerifyDiagnostics(); - CompileAndVerify(comp, expectedOutput: "123", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "123", verify: Verification.FailsIlVerify); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs index e253c4874a5c6..12bb018356b9b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs @@ -9603,7 +9603,7 @@ .locals init (int V_0, //a IL_0066: callvirt ""void <>A{00000004}.Invoke(System.Runtime.CompilerServices.CallSite, ref int, object)"" IL_006b: ret } -", verify: Verification.FailsIlVerify_TypedReference); // ILVerify doesn't support TypedReference +", verify: Verification.FailsIlVerify); // ILVerify doesn't support TypedReference } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs index 14462bede5c13..8febbd7ced1cf 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs @@ -3120,7 +3120,7 @@ public static void Main() // PEVerify: [ : Test::Main][mdToken=0x6000001][offset 0x00000009][found Native Int][expected unmanaged pointer] Unexpected type on the stack. var c = CompileAndVerifyUtil(text, options: TestOptions.UnsafeReleaseDll, - verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); + verify: Verification.FailsPeVerify); c.VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs index 1cbc296dbcb5a..f9f0b0165b54f 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs @@ -1385,7 +1385,7 @@ ref struct DisposableEnumerator public void Dispose() { System.Console.WriteLine(""Done with DisposableEnumerator""); } }"; // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @" 1 2 3 @@ -1449,7 +1449,7 @@ ref struct DisposableEnumerator public void Dispose(params object[] args) { System.Console.WriteLine($""Done with DisposableEnumerator. args was {args}, length {args.Length}""); } }"; // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @" 1 2 3 @@ -1484,7 +1484,7 @@ ref struct DisposableEnumerator public void Dispose(int arg = 1) { System.Console.WriteLine($""Done with DisposableEnumerator. arg was {arg}""); } }"; // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @" 1 2 3 @@ -1525,7 +1525,7 @@ static class DisposeExtension "; // extension methods do not contribute to disposal // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); + CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @"123"); } [Fact] @@ -1566,7 +1566,7 @@ static class DisposeExtension2 "; // extension methods do not contribute to disposal // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); + CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @"123"); } [Fact] @@ -1603,7 +1603,7 @@ static class DisposeExtension "; // extension methods do not contribute to disposal // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); + CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @"123"); } [Fact] @@ -1640,7 +1640,7 @@ static class DisposeExtension "; // extension methods do not contribute to disposal // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123"); + CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @"123"); } [Fact] @@ -1737,7 +1737,7 @@ ref struct DisposableEnumerator public void Dispose() { System.Console.WriteLine(""Done with DisposableEnumerator""); } }"; // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var compilation = CompileAndVerify(source, parseOptions: TestOptions.Regular7_3, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" + var compilation = CompileAndVerify(source, parseOptions: TestOptions.Regular7_3, verify: Verification.FailsIlVerify, expectedOutput: @" 1 2 3"); @@ -4734,7 +4734,7 @@ ref struct Enumerator public void Dispose() { Console.Write(""Disposed""); } }"; // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(source, parseOptions: TestOptions.Regular9, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @"123Disposed") + CompileAndVerify(source, parseOptions: TestOptions.Regular9, verify: Verification.FailsIlVerify, expectedOutput: @"123Disposed") .VerifyIL("C.Main", @" { // Code size 45 (0x2d) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs index f223188ffba46..c5ff33eeeb42f 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs @@ -1034,7 +1034,7 @@ public static void Main() } } "; - base.CompileAndVerify(source, verify: Verification.FailsIlVerify_TypedReference, expectedOutput: "12"). + base.CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: "12"). VerifyIL("Test.Main", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs index 5e5e1d85686fa..5b00142ccda9c 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs @@ -2387,7 +2387,7 @@ public System.Collections.IEnumerable SomeNumbers() }"; // The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available. var compilation = CreateEmptyCompilation(new[] { Parse(source), Parse(corlib) }); - var verifier = CompileAndVerify(compilation, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_ReturnFromCtor); + var verifier = CompileAndVerify(compilation, verify: Verification.Fails); verifier.VerifyDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1)); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs index 9f0a2a6f6aa48..2ebf0906ce15c 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs @@ -750,7 +750,7 @@ void Main() // Error: Token 0x02000009 following ELEMENT_TYPE_CLASS(_VALUETYPE) in signature is a ValueType (Class, respectively). // Type load failed. // ILVerify: Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType). + CompileAndVerify(comp, verify: Verification.Fails). VerifyIL("program.Main()", @" { @@ -879,7 +879,7 @@ void Main() // PEVerify: Type load failed. // ILVerify: Failed to load type 'System.String' from assembly ... - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed | Verification.FailsIlVerify_MissingStringType). + CompileAndVerify(comp, verify: Verification.Fails). VerifyIL("System.IntPtr..ctor(int)", @" { // Code size 10 (0xa) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs index b90346e2c0965..c1bec83718315 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs @@ -2556,7 +2556,7 @@ public static void Main() // from assembly 'Dev10, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' // is overriding a method that is not visible from that assembly. - CompileAndVerify(outerCompilation, verify: Verification.FailsPeVerify_UnableToResolveToken).VerifyIL("Test.Main", @" + CompileAndVerify(outerCompilation, verify: Verification.FailsPeVerify).VerifyIL("Test.Main", @" { // Code size 65 (0x41) .maxstack 4 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs index caa9dec8fb321..90ee8725449a2 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs @@ -554,7 +554,7 @@ public void SubmissionEntryPoint() "s0.dll", SyntaxFactory.ParseSyntaxTree(source0, options: TestOptions.Script), references); - var verifier = CompileAndVerify(s0, verify: Verification.FailsPeVerify_BadName); + var verifier = CompileAndVerify(s0, verify: Verification.FailsPeVerify); var methodData = verifier.TestData.GetMethodData(""); Assert.Equal("System.Threading.Tasks.Task", ((MethodSymbol)methodData.Method).ReturnType.ToDisplayString()); methodData.VerifyIL( diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs index d10679ea717c6..9ee83d7a9f6b7 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs @@ -5234,7 +5234,7 @@ public ref struct RefLike{} } "; // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var verifier = CompileAndVerify(source, verify: Verification.FailsIlVerify_BadReturnType, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- + var verifier = CompileAndVerify(source, verify: Verification.FailsIlVerify, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"--- M --- ---"); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs index b539119f504a5..5957b0a105e33 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs @@ -492,7 +492,7 @@ static void Main() CompileAndVerify(text, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_3), options: TestOptions.UnsafeReleaseExe, - verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.Main", + verify: Verification.FailsPeVerify).VerifyIL("C.Main", @"{ // Code size 8 (0x8) .maxstack 1 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index a845cfc9c96f9..ed70002e1d3c6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -260,7 +260,7 @@ static void Main(string[] args) } "; // ILVerify: Unexpected type on the stack. { Offset = 20, Found = readonly address of '[...]S1', Expected = address of '[...]S1' } - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, expectedOutput: @""); + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @""); compilation.VerifyIL("S1.Equals(object)", @" @@ -450,7 +450,7 @@ static void Main() } "; // ILVerify: Unexpected type on the stack. { Offset = 31, Found = readonly address of '[...]NS.N2.S`2', Expected = address of '[...]NS.N2.S`2' } - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, expectedOutput: @" + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: @" Abc 255 q"); @@ -2368,7 +2368,7 @@ static void Main(string[] args) "; // ILVerify: Unexpected type on the stack. { Offset = 10, Found = readonly address of '[...]C1', Expected = address of '[...]C1' } - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, expectedOutput: "0"); + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify, expectedOutput: "0"); compilation.VerifyIL("Program.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 657f387c33c24..6d17a65434e5d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -78,7 +78,7 @@ static void Main(object[] args) } }"; // ILVerify: Unexpected type on the stack. { Offset = 59, Found = readonly address of '[...]DoubleAndStruct', Expected = address of '[...]DoubleAndStruct' } - var result = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, options: TestOptions.DebugDll); + var result = CompileAndVerify(source, verify: Verification.FailsIlVerify, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -166,7 +166,7 @@ static void Main(object[] args) } }"; // ILVerify: Unexpected type on the stack. { Offset = 34, Found = readonly address of '[...]OuterStruct', Expected = address of '[...]OuterStruct' } - var result = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, options: TestOptions.DebugDll); + var result = CompileAndVerify(source, verify: Verification.FailsIlVerify, options: TestOptions.DebugDll); result.VerifyIL("Program.Main(object[])", @" @@ -4361,7 +4361,7 @@ public static void M() Callee3(default(T), default(T)); } } -", verify: Verification.FailsPeVerify_TypeDevNotNil, options: TestOptions.ReleaseExe); +", verify: Verification.FailsPeVerify, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 297 (0x129) @@ -4494,7 +4494,7 @@ public static void M() Callee3(); } } -", verify: Verification.FailsPeVerify_TypeDevNotNil, options: TestOptions.ReleaseExe); +", verify: Verification.FailsPeVerify, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 34 (0x22) @@ -5267,7 +5267,7 @@ static void Test(in T r) // ILVerify: // Unexpected type on the stack. { Offset = 9, Found = readonly address of 'T', Expected = address of 'T' } // Unexpected type on the stack. { Offset = 23, Found = readonly address of 'T', Expected = address of 'T' } - var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack | Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.Fails); var expectedIL = @" { @@ -5288,7 +5288,7 @@ .maxstack 2 compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); // expect the same IL in the compat case since direct references are required and must be emitted with "readonly.", even though unverifiable - compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack | Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); + compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.Fails, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); } @@ -10466,7 +10466,7 @@ static void Main() Diagnostic(ErrorCode.WRN_ExternMethodNoImplementation, "Goo").WithArguments("Test.Goo()")); // NOTE: the resulting IL is unverifiable, but not an error for compat reasons - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed).VerifyIL("Test.Main", + CompileAndVerify(comp, verify: Verification.FailsPeVerify).VerifyIL("Test.Main", @" { // Code size 11 (0xb) @@ -17224,7 +17224,7 @@ static async Task MethodAsync() System.Threading.Tasks.Task`1[System.Object] Success True -", verify: Verification.FailsIlVerify_TypedReference).VerifyDiagnostics(); +", verify: Verification.FailsIlVerify).VerifyDiagnostics(); } } } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs index b4eeffdd5b405..d12a2085927e5 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs @@ -698,7 +698,7 @@ public class B : A Diagnostic(ErrorCode.WRN_FinalizeMethod, "Finalize")); // We produce unverifiable code here as per bug resolution (compat concerns, not common case). - CompileAndVerify(compilation, verify: Verification.FailsPeVerify_TypeLoadFailed).VerifyIL("B.Finalize", + CompileAndVerify(compilation, verify: Verification.FailsPeVerify).VerifyIL("B.Finalize", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs index 7a2ae9e47797d..adce2b4b79b8b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs @@ -4109,7 +4109,7 @@ static void Main() // PEVerify: // Error: Assembly name contains leading spaces or path or extension. // Type load failed. - var verifier = CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed); + var verifier = CompileAndVerify(comp, verify: Verification.FailsPeVerify); verifier.VerifyIL("Program.Main", @" { // Code size 223 (0xdf) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index a97a1ff2deedb..11d793712eeb5 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -5812,7 +5812,7 @@ void M(int* pi, void* pv, sbyte sb, byte b, short s, ushort us, int i, uint ui, } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.M", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify).VerifyIL("C.M", @" { // Code size 79 (0x4f) .maxstack 1 @@ -5902,7 +5902,7 @@ void M(int* pi, void* pv, sbyte sb, byte b, short s, ushort us, int i, uint ui, } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.M", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify).VerifyIL("C.M", @" { // Code size 79 (0x4f) .maxstack 1 @@ -6499,7 +6499,7 @@ static void Main() } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "1234", verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.Main", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "1234", verify: Verification.FailsPeVerify).VerifyIL("C.Main", @" { // Code size 120 (0x78) .maxstack 5 @@ -9784,7 +9784,7 @@ public static implicit operator C(int* p) } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyIL("C.M", @" + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify).VerifyIL("C.M", @" { // Code size 12 (0xc) .maxstack 1 @@ -10150,7 +10150,7 @@ No overflow from (S15*)0 + sizeof(S16) // [ : C+<>c__DisplayClass0_0::
b__0][mdToken=0x6000005][offset 0x00000012][found Native Int][expected unmanaged pointer] Unexpected type on the stack. // [ : C+<> c__DisplayClass0_0::< Main > b__1][mdToken= 0x6000006][offset 0x00000012][found Native Int][expected unmanaged pointer] Unexpected type on the stack. // [ : C +<> c__DisplayClass0_0::< Main > b__2][mdToken = 0x6000007][offset 0x00000012][found Native Int][expected unmanaged pointer] Unexpected type on the stack. - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify); } [Fact] @@ -10334,7 +10334,7 @@ public static void Main() // PEVerify: // [ : ChannelServices::.cctor][mdToken=0x6000005][offset 0x0000000C][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack. // [ : ChannelServices::GetPrivateContextsPerfCounters][mdToken= 0x6000002][offset 0x00000002][found Native Int][expected unmanaged pointer] Unexpected type on the stack. - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics(); + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.FailsPeVerify).VerifyDiagnostics(); } [WorkItem(545026, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545026")] @@ -10350,7 +10350,7 @@ class C "; // PEVerify: // [ : C::.ctor][mdToken=0x6000001][offset 0x0000000A][found Native Int][expected unmanaged pointer] Unexpected type on the stack. - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify).VerifyDiagnostics( // (4,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); @@ -10369,7 +10369,7 @@ class C "; // PEVerify: // [ : C::.ctor][mdToken=0x6000001][offset 0x00000003][found Native Int][expected unmanaged pointer] Unexpected type on the stack. - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify).VerifyDiagnostics( // (5,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); @@ -10854,7 +10854,7 @@ unsafe struct S1 "; - var verifier = CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll.WithConcurrentBuild(false), verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); + var verifier = CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll.WithConcurrentBuild(false), verify: Verification.FailsPeVerify); } [Fact, WorkItem(748530, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/748530")] @@ -11373,7 +11373,7 @@ public static unsafe int Test(params int*[] types) // PEVerify: // [ : Program::Main][mdToken= 0x6000001][offset 0x00000001] Unmanaged pointers are not a verifiable type. // [ : Program::Main][mdToken = 0x6000001][offset 0x00000001] Unable to resolve token. - var comp = CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: "0", verify: Verification.FailsPeVerify_UnableToResolveToken); + var comp = CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: "0", verify: Verification.FailsPeVerify); comp.VerifyIL("Program.Main", @" { // Code size 17 (0x11) diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index d0352fc46a280..cf1cfd7721c4c 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4309,7 +4309,7 @@ public void EmitNetModuleWithReferencedNetModule() string source2 = @"public class B: A {}"; var comp = CreateCompilation(source1, options: TestOptions.ReleaseModule); var metadataRef = ModuleMetadata.CreateFromStream(comp.EmitToStream()).GetReference(); - CompileAndVerify(source2, references: new[] { metadataRef }, options: TestOptions.ReleaseModule, verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage); + CompileAndVerify(source2, references: new[] { metadataRef }, options: TestOptions.ReleaseModule, verify: Verification.Fails); } [ConditionalFact(typeof(WindowsOnly), Reason = "https://github.com/dotnet/roslyn/issues/30169")] @@ -5232,7 +5232,7 @@ public void CompileAndVerifyModuleIncludesAllModules() var comp = CreateCompilation("public class B : A { }", references: new[] { modRef }, assemblyName: "sourceMod"); // ILVerify: Assembly or module not found: refMod - CompileAndVerify(comp, verify: Verification.FailsIlVerify_MissingAssembly, symbolValidator: module => + CompileAndVerify(comp, verify: Verification.FailsIlVerify, symbolValidator: module => { var b = module.GlobalNamespace.GetTypeMember("B"); Assert.Equal("B", b.Name); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs index 1770dce00177f..0256b5cfa1f27 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs @@ -5107,7 +5107,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); @@ -5166,7 +5166,7 @@ public async Task F() // older versions of mscorlib don't contain IteratorStateMachineAttribute Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5230,7 +5230,7 @@ public async Task F() Assert.NotNull(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5331,7 +5331,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify_TypeLoadFailed); + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsPeVerify); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs index 6826b90ec8674..33c5ac9648790 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitCustomModifiers.cs @@ -705,7 +705,7 @@ static void Main() }"; var compilation = CreateCompilationWithILAndMscorlib40(source, ilSource, options: TestOptions.UnsafeReleaseExe); compilation.VerifyDiagnostics(); - CompileAndVerify(compilation, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); + CompileAndVerify(compilation, verify: Verification.FailsPeVerify); } [Fact] @@ -739,7 +739,7 @@ static void Main() }"; var compilation = CreateCompilationWithILAndMscorlib40(source, ilSource, options: TestOptions.UnsafeReleaseExe); compilation.VerifyDiagnostics(); - CompileAndVerify(compilation, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); + CompileAndVerify(compilation, verify: Verification.FailsPeVerify); } } } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs index f0e5d2b710714..59d42c515c1ed 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs @@ -206,7 +206,7 @@ public class Test : Class2 { } "; - CompileAndVerifyWithMscorlib40(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, verify: Verification.FailsIlVerify_NotImplemented, assemblyValidator: (assembly) => + CompileAndVerifyWithMscorlib40(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, verify: Verification.FailsIlVerify, assemblyValidator: (assembly) => { var refs2 = assembly.Modules[0].ReferencedAssemblies.Select(r => r.Name); Assert.Equal(2, refs2.Count()); @@ -226,7 +226,7 @@ public void Bug687434() { CompileAndVerify( "public class C { }", - verify: Verification.FailsPeVerify_MissingManifest | Verification.FailsIlVerify_BadImage, + verify: Verification.Fails, options: TestOptions.DebugDll.WithOutputKind(OutputKind.NetModule)); } @@ -243,7 +243,7 @@ public class Test : Class1 "; // modules not supported in ref emit // ILVerify: Assembly or module not found: netModule1 - CompileAndVerify(source, new[] { netModule1, netModule2 }, verify: Verification.FailsIlVerify_MissingAssembly, assemblyValidator: (assembly) => + CompileAndVerify(source, new[] { netModule1, netModule2 }, verify: Verification.FailsIlVerify, assemblyValidator: (assembly) => { Assert.Equal(3, assembly.Modules.Length); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs index 7c5cd97c611e4..c9361d66153ff 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs @@ -1779,9 +1779,9 @@ interface UsePia5 : ITest29 Assert.Equal(VarianceKind.None, t7.Variance); }; - CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify); - CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.FailsPeVerify); } [Fact] @@ -4708,11 +4708,11 @@ public void M1() var compilation3 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation3, verify: Verification.FailsPeVerify); var compilation4 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation4, verify: Verification.FailsPeVerify); } [Fact] @@ -5185,11 +5185,11 @@ public void M1() var compilation3 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation3, verify: Verification.FailsPeVerify); var compilation4 = CreateCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation4, verify: Verification.FailsPeVerify); } [ConditionalFact(typeof(ClrOnly), Reason = ConditionalSkipReason.NoPiaNeedsDesktop)] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs index f0d2fbc5d588c..7683be1a89c69 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs @@ -190,7 +190,7 @@ .locals init (int V_0) //i IL_0013: ret }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "System.Int32", verify: Verification.FailsIlVerify_TypedReference); + var verifier = CompileAndVerify(source: text, expectedOutput: "System.Int32", verify: Verification.FailsIlVerify); verifier.VerifyIL("C.Main", expectedIL); } @@ -358,7 +358,7 @@ .maxstack 1 IL_0008: ret }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "System.String", verify: Verification.FailsIlVerify_TypedReference); + var verifier = CompileAndVerify(source: text, expectedOutput: "System.String", verify: Verification.FailsIlVerify); verifier.VerifyIL("C.M", expectedIL); } @@ -673,7 +673,7 @@ .maxstack 2 IL_000c: ret }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "1123", verify: Verification.FailsIlVerify_TypedReference); + var verifier = CompileAndVerify(source: text, expectedOutput: "1123", verify: Verification.FailsIlVerify); verifier.VerifyIL("C.Get", expectedGetIL); verifier.VerifyIL("C.Set", expectedSetIL); verifier.VerifyIL("C.Ref", expectedRefIL); @@ -795,7 +795,7 @@ .locals init (int V_0, //x 42 333 0 -42", verify: Verification.FailsIlVerify_TypedReference); +42", verify: Verification.FailsIlVerify); verifier.VerifyIL("Program.Main", expectedGetIL); } @@ -903,7 +903,7 @@ static void Main() } }"; - var verifier = CompileAndVerify(source: text, expectedOutput: "4242", verify: Verification.FailsIlVerify_TypedReference); + var verifier = CompileAndVerify(source: text, expectedOutput: "4242", verify: Verification.FailsIlVerify); verifier.VerifyIL("C.Main", @" { // Code size 72 (0x48) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs index b2dcfa8dcbf1d..42c5f2bc50356 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BetterCandidates.cs @@ -863,7 +863,7 @@ public class ExtensionAttribute : System.Attribute {} var compilation = CreateCompilationWithBetterCandidates(source, options: TestOptions.ReleaseExe).VerifyDiagnostics( ); // ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(compilation, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: "2"); + CompileAndVerify(compilation, verify: Verification.FailsIlVerify, expectedOutput: "2"); } // Test suggested by @VSadov diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs index dad5b429f5bfe..f483ca9c30f9b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs @@ -1588,11 +1588,11 @@ public static void M(MyResult r) var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); compilation.VerifyDiagnostics(); // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(compilation, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: "3"); + CompileAndVerify(compilation, verify: Verification.FailsIlVerify, expectedOutput: "3"); compilation = CreateCompilation(source, options: TestOptions.DebugExe); compilation.VerifyDiagnostics(); - CompileAndVerify(compilation, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: "3"); + CompileAndVerify(compilation, verify: Verification.FailsIlVerify, expectedOutput: "3"); } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs index 6356bc9ab5c1d..59b1d0281411d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs @@ -1299,7 +1299,7 @@ static class B if (expectedDiagnostics is null) { // ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: $"{expectedMethod}: {expectedType}"); + CompileAndVerify(comp, verify: Verification.FailsIlVerify, expectedOutput: $"{expectedMethod}: {expectedType}"); } else { @@ -1394,7 +1394,7 @@ static class B if (expectedDiagnostics is null) { // ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: $"{expectedMethod}: {expectedType}"); + CompileAndVerify(comp, verify: Verification.FailsIlVerify, expectedOutput: $"{expectedMethod}: {expectedType}"); } else { @@ -1770,7 +1770,7 @@ static void Main() }"; var comp = CreateCompilation(new[] { source, s_utils }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); // ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: "System.Action, System.Action"); + CompileAndVerify(comp, verify: Verification.FailsIlVerify, expectedOutput: "System.Action, System.Action"); var tree = comp.SyntaxTrees[0]; var model = comp.GetSemanticModel(tree); @@ -7873,7 +7873,7 @@ static class E comp.VerifyDiagnostics(); // ILVerify: Unrecognized arguments for delegate .ctor. - var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: @"(41, 42)"); + var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify, expectedOutput: @"(41, 42)"); verifier.VerifyIL("Program.M1", @"{ // Code size 20 (0x14) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs index d517d5e9193a0..d0ee5ca79c534 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs @@ -3604,7 +3604,7 @@ unsafe static void Main() } "; // PEVerify: [ : Program::Main][mdToken=0x6000001][offset 0x0000002C][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack. - var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics(); + var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.FailsPeVerify).VerifyDiagnostics(); var tree = verifier.Compilation.SyntaxTrees.Single(); var model = verifier.Compilation.GetSemanticModel(tree); @@ -3632,7 +3632,7 @@ unsafe static void Main() } "; // PEVerify: [ : Program::Main][mdToken=0x6000001][offset 0x0000002C][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack. - var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.FailsPeVerify_UnexpectedTypeOnStack).VerifyDiagnostics(); + var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.FailsPeVerify).VerifyDiagnostics(); var tree = verifier.Compilation.SyntaxTrees.Single(); var model = verifier.Compilation.GetSemanticModel(tree); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs index d654c504e2bf6..3baa1feda2708 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs @@ -3073,7 +3073,7 @@ static void M(string s) }"; var comp = CreateEmptyCompilation(text, new[] { reference1 }); - CompileAndVerify(comp, verify: Verification.FailsPeVerify_TypeLoadFailed). + CompileAndVerify(comp, verify: Verification.FailsPeVerify). VerifyIL("C.M", @" { // Code size 28 (0x1c) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs index 3313599b45ff2..908b441d03615 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs @@ -2660,7 +2660,7 @@ static void Test1(delegate*[] func) { System.Console.Write(t); } } -", expectedOutput: "11", options: TestOptions.UnsafeReleaseExe, verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify_UnspecifiedError : Verification.Skipped); +", expectedOutput: "11", options: TestOptions.UnsafeReleaseExe, verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify : Verification.Skipped); verifier.VerifyIL("", @" { diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs index fd8ae9d0ac30e..f37d3fb689a2a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs @@ -1440,7 +1440,7 @@ public class C // PE verification fails: [ : C::set_Property] Cannot change initonly field outside its .ctor. CompileAndVerify(comp, sourceSymbolValidator: symbolValidator, symbolValidator: symbolValidator, - verify: Verification.Fails_InitOnly); + verify: Verification.Fails); void symbolValidator(ModuleSymbol m) { @@ -2732,7 +2732,7 @@ public int Property comp.VerifyDiagnostics(); // [ : C::set_Property] Cannot change initonly field outside its .ctor. CompileAndVerify(comp, expectedOutput: "42 43", - verify: Verification.Fails_InitOnly); + verify: Verification.Fails); } [Fact] @@ -4181,7 +4181,7 @@ public static void Main() targetFramework: TargetFramework.Mscorlib40, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular9); // PEVerify: [ : S::set_Property] Cannot change initonly field outside its .ctor. CompileAndVerify(comp1, expectedOutput: "42", - verify: Verification.Fails_InitOnly); + verify: Verification.Fails); var comp1Ref = new[] { comp1.ToMetadataReference() }; var comp7 = CreateCompilation(source2, references: comp1Ref, @@ -4205,7 +4205,7 @@ public readonly struct S { public int I { get; init; } } -" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); +" }, verify: Verification.Fails, expectedOutput: "1"); @@ -4243,7 +4243,7 @@ public readonly struct S private readonly int i; public int I { get => i; init => i = value; } } -" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); +" }, verify: Verification.Fails, expectedOutput: "1"); var s = verifier.Compilation.GetTypeByMetadataName("S"); var i = s.GetMember("I"); @@ -4282,7 +4282,7 @@ public struct S { public readonly int I { get; init; } } -" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); +" }, verify: Verification.Fails, expectedOutput: "1"); var s = verifier.Compilation.GetTypeByMetadataName("S"); var i = s.GetMember("I"); @@ -4322,7 +4322,7 @@ public struct S private readonly int i; public readonly int I { get => i; init => i = value; } } -" }, verify: Verification.Fails_InitOnly, expectedOutput: "1"); +" }, verify: Verification.Fails, expectedOutput: "1"); var s = verifier.Compilation.GetTypeByMetadataName("S"); var i = s.GetMember("I"); @@ -4417,7 +4417,7 @@ public int I2 } } } -" }, verify: Verification.Fails_InitOnly, expectedOutput: @"I1 was 1 +" }, verify: Verification.Fails, expectedOutput: @"I1 was 1 I1 is 0"); var s = verifier.Compilation.GetTypeByMetadataName("S"); @@ -4551,7 +4551,7 @@ public record Container(Person Person); var comp = CreateCompilation(new[] { IsExternalInitTypeDefinition, source }, options: TestOptions.DebugExe); comp.VerifyEmitDiagnostics(); // PEVerify: Cannot change initonly field outside its .ctor. - CompileAndVerify(comp, expectedOutput: "c", verify: Verification.Fails_InitOnly); + CompileAndVerify(comp, expectedOutput: "c", verify: Verification.Fails); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index fb6c35a14e567..f253c05aa7a95 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -3819,7 +3819,7 @@ class C var comp = CreateCompilation(new[] { source, interpolatedStringBuilder }, targetFramework: TargetFramework.NetCoreApp); // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: @" + var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify, expectedOutput: @" value:S converted value:C"); @@ -9220,7 +9220,7 @@ public CustomHandler(int literalLength, int formattedCount," + refness + @" C c) expectedOutput: "1literal:literal", symbolValidator: validator, sourceSymbolValidator: validator, - verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify_BadReturnType : Verification.Skipped); + verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify : Verification.Skipped); verifier.VerifyIL("", refness == "in" ? @" { // Code size 46 (0x2e) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs index f7bcb86a9d8ae..c8cb5e725adb0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs @@ -772,7 +772,7 @@ static void Main() // default(IntPtr) as "load zero, convert to type", rather than making a stack slot and calling // init on it. - var c = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify_UnexpectedTypeOnStack); + var c = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll, verify: Verification.FailsPeVerify); c.VerifyIL("C.Main", @"{ // Code size 13 (0xd) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index cfc9bbc0dea86..91de5e67edb46 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -112195,7 +112195,7 @@ interface I2 compilation2.VerifyEmitDiagnostics(); // Verification against a corlib not named exactly mscorlib is expected to fail. - CompileAndVerify(compilation2, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation2, verify: Verification.FailsPeVerify); Assert.Equal(TypeKind.Struct, compilation2.GetTypeByMetadataName("A").TypeKind); Assert.Equal(TypeKind.Enum, compilation2.GetTypeByMetadataName("B").TypeKind); @@ -112206,7 +112206,7 @@ interface I2 var compilation3 = CreateEmptyCompilation(source2, options: WithNullableEnable(TestOptions.ReleaseDll), references: new[] { compilation1.ToMetadataReference(), MinCorlibRef }); compilation3.VerifyEmitDiagnostics(); - CompileAndVerify(compilation3, verify: Verification.FailsPeVerify_TypeLoadFailed); + CompileAndVerify(compilation3, verify: Verification.FailsPeVerify); Assert.Equal(TypeKind.Struct, compilation3.GetTypeByMetadataName("A").TypeKind); Assert.Equal(TypeKind.Enum, compilation3.GetTypeByMetadataName("B").TypeKind); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs index b1b6b33d44959..cfd0f08e4e75d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs @@ -9038,7 +9038,7 @@ public static void RemoveDetail(this TMain main, TChild child) }"; var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe); // ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(compilation, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: + CompileAndVerify(compilation, verify: Verification.FailsIlVerify, expectedOutput: @"RemoveDetail RemoveDetail RemoveDetail @@ -11294,7 +11294,7 @@ private static bool Contains(this System.Collections.Generic.IEnumerable a }"; // ILVerify: Unrecognized arguments for delegate .ctor. - CompileAndVerify(code, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate, expectedOutput: @"2"); + CompileAndVerify(code, verify: Verification.FailsIlVerify, expectedOutput: @"2"); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index e9ec0bd2cd332..6a92f56bb1a57 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -6221,7 +6221,7 @@ static int CopyRefInt(ref int z) var compilation = CreateCompilation(program, options: TestOptions.DebugExe.WithAllowUnsafe(true)); compilation.VerifyDiagnostics( ); - var comp = CompileAndVerify(compilation, expectedOutput: "ok", verify: Verification.FailsIlVerify_TypedReference); + var comp = CompileAndVerify(compilation, expectedOutput: "ok", verify: Verification.FailsIlVerify); } [Fact] @@ -6520,7 +6520,7 @@ unsafe static void Main() // PEVerify: // [ : Program::Main][mdToken=0x6000001][offset 0x00000002] Unmanaged pointers are not a verifiable type. // [ : Program::Main][mdToken= 0x6000001][offset 0x00000002] Unable to resolve token. - CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify_UnableToResolveToken); + CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.FailsPeVerify); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs index bc391bcfbb73a..185409fb70664 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs @@ -471,7 +471,7 @@ public static RGBColor FromRainbow(Rainbow colorBand) => compilation.VerifyDiagnostics( ); // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - var comp = CompileAndVerify(compilation, verify: Verification.FailsIlVerify_BadReturnType, expectedOutput: expectedOutput); + var comp = CompileAndVerify(compilation, verify: Verification.FailsIlVerify, expectedOutput: expectedOutput); } [Fact, WorkItem(35278, "https://github.com/dotnet/roslyn/issues/35278")] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs index 005a57db82f60..569f9a1d9d066 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs @@ -2364,7 +2364,7 @@ public static void Main() "; var compilation = CreateCompilation(new[] { source, TestSources.Index }, options: TestOptions.ReleaseExe); compilation.VerifyEmitDiagnostics(); - CompileAndVerify(compilation, expectedOutput: "123", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(compilation, expectedOutput: "123", verify: Verification.FailsIlVerify); } [Fact] @@ -3504,7 +3504,7 @@ public class C "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyDiagnostics(); - CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.FailsIlVerify); } [Fact] @@ -5051,7 +5051,7 @@ void M2() "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyEmitDiagnostics(); - var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)", verify: Verification.FailsIlVerify); verifier.VerifyIL("C.M", @" { @@ -5139,7 +5139,7 @@ void M2() "; var compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); compilation.VerifyEmitDiagnostics(); - var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var verifier = CompileAndVerify(compilation, expectedOutput: "(item value, rest value)", verify: Verification.FailsIlVerify); verifier.VerifyIL("C.M", @" { @@ -5228,7 +5228,7 @@ static void Main() Console.Write((x, y)); } }"; - CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "Index Range (42, 43)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "Index Range (42, 43)", verify: Verification.FailsIlVerify); } [Fact] @@ -5267,7 +5267,7 @@ public void SlicePattern_String() System.Console.Write((first, rest).ToString()); } "; - CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "(a, bc)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(new[] { src, TestSources.Index, TestSources.Range }, expectedOutput: "(a, bc)", verify: Verification.FailsIlVerify); } [Fact] @@ -7068,7 +7068,7 @@ public string M() } } "; - var verifier = CompileAndVerify(new[] { source, TestSources.Index }, options: TestOptions.DebugDll, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var verifier = CompileAndVerify(new[] { source, TestSources.Index }, options: TestOptions.DebugDll, verify: Verification.FailsIlVerify); verifier.VerifyIL("C.M", @" { // Code size 105 (0x69) @@ -7165,7 +7165,7 @@ public string M() } } "; - var verifier = CompileAndVerify(new[] { source, TestSources.Index }, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var verifier = CompileAndVerify(new[] { source, TestSources.Index }, verify: Verification.FailsIlVerify); verifier.VerifyIL("C.M", @" { // Code size 78 (0x4e) @@ -7314,7 +7314,7 @@ public void M() ); compilation = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); - var verifier = CompileAndVerify(compilation, expectedOutput: "(2, 3)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var verifier = CompileAndVerify(compilation, expectedOutput: "(2, 3)", verify: Verification.FailsIlVerify); verifier.VerifyDiagnostics(); // Note: no Index or Range involved verifier.VerifyIL("C.M", @" @@ -7560,7 +7560,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify); } [Fact] @@ -7606,7 +7606,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify); } [Fact] @@ -7620,7 +7620,7 @@ public void Simple_String() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(4, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(4, 2)", verify: Verification.FailsIlVerify); } [Fact] @@ -7635,7 +7635,7 @@ public void Simple_Array() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(4, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(4, 2)", verify: Verification.FailsIlVerify); } [Theory] @@ -7656,7 +7656,7 @@ public void Simple_Array_VerifyIndexMaths(string data, string pattern, string el "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(4, 4)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(4, 4)", verify: Verification.FailsIlVerify); } [Fact] @@ -7677,7 +7677,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify); } [Fact] @@ -7698,7 +7698,7 @@ class C "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(42, 42)", verify: Verification.FailsIlVerify); } [Fact] @@ -7712,7 +7712,7 @@ public void Simple_String_Slice() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "42", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "42", verify: Verification.FailsIlVerify); } [Fact, WorkItem(57728, "https://github.com/dotnet/roslyn/issues/57728")] @@ -7733,7 +7733,7 @@ public static void Main() "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }, options: TestOptions.ReleaseExe); comp.VerifyEmitDiagnostics(); - var verifier = CompileAndVerify(comp, expectedOutput: "(4, 2, 4, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var verifier = CompileAndVerify(comp, expectedOutput: "(4, 2, 4, 2)", verify: Verification.FailsIlVerify); // we use Array.Length to get the length, but should be using ldlen // Tracked by https://github.com/dotnet/roslyn/issues/57728 verifier.VerifyIL("C.Main", @" @@ -7825,7 +7825,7 @@ public void Simple_Array_Slice_VerifyRangeMaths(string data, string pattern, str "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "(4, 2, 2, 4, 2, 2)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + CompileAndVerify(comp, expectedOutput: "(4, 2, 2, 4, 2, 2)", verify: Verification.FailsIlVerify); } [Fact] @@ -7847,7 +7847,7 @@ public int M(int[] a) "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range, TestSources.GetSubArray }, options: TestOptions.ReleaseDll); // ILVerify: Unexpected type on the stack. { Offset = 20, Found = readonly address of '[...]System.Index', Expected = address of '[...]System.Index' } - var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack).VerifyDiagnostics(); + var verifier = CompileAndVerify(comp, verify: Verification.FailsIlVerify).VerifyDiagnostics(); verifier.VerifyIL("C.M", @" { @@ -7923,7 +7923,7 @@ class C : Interface } "; var comp = CreateCompilation(new[] { source, TestSources.Index, TestSources.Range }); - var verifier = CompileAndVerify(comp, expectedOutput: "(42, 43)", verify: Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack); + var verifier = CompileAndVerify(comp, expectedOutput: "(42, 43)", verify: Verification.FailsIlVerify); verifier.VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs index e47c4a0d1edcb..23012acfeaf60 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs @@ -1851,7 +1851,7 @@ static void Main() CSharpCompilation comp = CreateCompilationWithMscorlibAndSpan(text, options: TestOptions.DebugExe); // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - CompileAndVerify(comp, expectedOutput: "Done", verify: Verification.FailsIlVerify_BadReturnType).VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "Done", verify: Verification.FailsIlVerify).VerifyDiagnostics(); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs index 630552b84173a..a9f02223a952b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs @@ -1885,7 +1885,7 @@ static void Main() "; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_1, options: TestOptions.DebugExe); comp.VerifyDiagnostics(); - CompileAndVerify(comp, expectedOutput: "123: True", verify: Verification.FailsIlVerify_TypedReference); + CompileAndVerify(comp, expectedOutput: "123: True", verify: Verification.FailsIlVerify); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs index 354a057591127..0981e9e881325 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs @@ -1025,7 +1025,7 @@ public static void Main(string[] args) { }); assembly.VerifyEmitDiagnostics(); // ILVerify: Assembly or module not found: a2 - CompileAndVerify(assembly, verify: Verification.FailsIlVerify_MissingAssembly); + CompileAndVerify(assembly, verify: Verification.FailsIlVerify); } [WorkItem(713356, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/713356")] diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs index 43708a2bd286a..505c638d32ac3 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/UsedAssembliesTests.cs @@ -32,7 +32,7 @@ interface I1 } "; var comp1 = CreateEmptyCompilation(source); - CompileAndVerify(comp1, verify: Verification.FailsIlVerify_MissingStringType); + CompileAndVerify(comp1, verify: Verification.FailsIlVerify); Assert.Empty(comp1.GetUsedAssemblyReferences()); @@ -53,7 +53,7 @@ public interface I1 } "; var comp1 = CreateEmptyCompilation(source); - CompileAndVerify(comp1, verify: Verification.FailsIlVerify_MissingStringType); + CompileAndVerify(comp1, verify: Verification.FailsIlVerify); var source2 = @" @@ -411,7 +411,7 @@ public interface I1 } "; var comp1 = CreateEmptyCompilation(source); - CompileAndVerify(comp1, verify: Verification.FailsIlVerify_MissingStringType); + CompileAndVerify(comp1, verify: Verification.FailsIlVerify); var source2 = @" diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs index d7ab72b4a34fe..aba60f5b301c9 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs @@ -44,15 +44,17 @@ private static Verification VerifyOnMonoOrCoreClr { get { + // TODO2 return ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.Passes : Verification.Skipped; } } - private static Verification VerifyOnMonoOrCoreClr_NotVisible + private static Verification VerifyOnMonoOrCoreClr_Fails { get { - return ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify_NotVisible : Verification.Skipped; + // TODO2 + return ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify : Verification.Skipped; } } @@ -9646,7 +9648,7 @@ static void Main() M2 M3", symbolValidator: validate, - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr_Fails); validate(compilation1.SourceModule); @@ -9710,7 +9712,7 @@ static void Main() CompileAndVerify(compilation4, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1 M2", - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr_Fails); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -17962,7 +17964,7 @@ static void Main() get_P6 set_P6", symbolValidator: validate, - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr_Fails); validate(compilation1.SourceModule); @@ -18071,7 +18073,7 @@ static void Main() set_P5 set_P6 ", - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr_Fails); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -28452,7 +28454,7 @@ static void Main() get_P2 set_P2 get_P3 -set_P3", symbolValidator: validate, verify: VerifyOnMonoOrCoreClr_NotVisible); +set_P3", symbolValidator: validate, verify: VerifyOnMonoOrCoreClr_Fails); validate(compilation1.SourceModule); @@ -28525,7 +28527,7 @@ static void Main() set_P1 get_P2 set_P2", - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr_Fails); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29267,7 +29269,7 @@ public void M1() } "; - ValidateNestedTypes_01(source0 + source1, Accessibility.Protected, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_NotVisible); + ValidateNestedTypes_01(source0 + source1, Accessibility.Protected, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_Fails); var compilation1 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular, @@ -29373,7 +29375,7 @@ public void M1() I1+T3 B I1+T5", - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr_Fails); var compilation5 = CreateCompilation(source2, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29508,7 +29510,7 @@ public void M1() I1+T3 B I1+T5", - verify: VerifyOnMonoOrCoreClr_NotVisible); + verify: VerifyOnMonoOrCoreClr_Fails); var compilation5 = CreateCompilation(source2, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29817,7 +29819,7 @@ public void M1() } } "; - ValidateNestedTypes_01(source0 + source1, Accessibility.ProtectedAndInternal, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_NotVisible); + ValidateNestedTypes_01(source0 + source1, Accessibility.ProtectedAndInternal, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_Fails); var compilation1 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular, @@ -32827,7 +32829,7 @@ static void Main() @"I2.M1 I4.M1 ", - verify: VerifyOnMonoOrCoreClr_NotVisible, + verify: VerifyOnMonoOrCoreClr_Fails, symbolValidator: ValidateMethodImplementationInDerived_01); foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) @@ -33073,7 +33075,7 @@ static void Main() @"I2.M1 I4.M1 ", - verify: VerifyOnMonoOrCoreClr_NotVisible, + verify: VerifyOnMonoOrCoreClr_Fails, symbolValidator: ValidateMethodImplementationInDerived_01); foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) @@ -38936,7 +38938,7 @@ public static void Test() @"123 -2 ", - verify: VerifyOnMonoOrCoreClr_NotVisible, symbolValidator: validate); + verify: VerifyOnMonoOrCoreClr_Fails, symbolValidator: validate); var source2 = @" @@ -38958,7 +38960,7 @@ static void Main() parseOptions: TestOptions.Regular, targetFramework: TargetFramework.NetCoreApp); - CompileAndVerify(compilation2, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "1122" : null, verify: VerifyOnMonoOrCoreClr_NotVisible); + CompileAndVerify(compilation2, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "1122" : null, verify: VerifyOnMonoOrCoreClr_Fails); } var source3 = @@ -44787,7 +44789,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); var source2 = @" interface I2 : I3 @@ -44813,7 +44815,7 @@ static void Main() var compilation1 = CreateCompilation(source0 + source2, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation1.VerifyDiagnostics(); - CompileAndVerify(compilation1, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); + CompileAndVerify(compilation1, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); var source3 = @" interface I2 : I3 @@ -44950,7 +44952,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); var source3 = @" class I2 @@ -45010,7 +45012,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_NotVisible); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); } private const string NoPiaAttributes = @" diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs index 6f1c6f6d2eeac..be69a949aaac3 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs @@ -294,7 +294,7 @@ static void Goo(this string x) @"ABC 123 123 -xyz", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); +xyz", verify: Verification.FailsIlVerify); } [WorkItem(541143, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541143")] @@ -376,7 +376,7 @@ static void Main() static void Goo(this T x) { } } "; - CompileAndVerify(source, expectedOutput: "2", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); + CompileAndVerify(source, expectedOutput: "2", verify: Verification.FailsIlVerify); } [WorkItem(528426, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/528426")] @@ -873,7 +873,7 @@ internal static void F(this object o) { } internal static void F(this object x, object y) { } internal static void G(this object x, object y) { } }"; - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify); compilation.VerifyIL("N.C.M", @"{ // Code size 71 (0x47) @@ -939,7 +939,7 @@ internal static void F2(this object x, object y) { } internal static void F3(this object x, int y) { } internal static void F4(this object x, object y) { } }"; - var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); + var compilation = CompileAndVerify(source, verify: Verification.FailsIlVerify); compilation.VerifyIL("N.C.M", @" { @@ -1923,7 +1923,7 @@ public static void M(this C c, int i) System.Console.Write(c.P * i); } }"; - CompileAndVerify(source, expectedOutput: "6", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); + CompileAndVerify(source, expectedOutput: "6", verify: Verification.FailsIlVerify); } [Fact] @@ -2298,7 +2298,7 @@ static void M(Action a) @"F: System.Int32 F: S G: System.Int32 -G: S", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); +G: S", verify: Verification.FailsIlVerify); compilation.VerifyIL("C.Main", @"{ // Code size 105 (0x69) @@ -2379,7 +2379,7 @@ internal static void M(this object o) System.Object System.Int32 B -B", verify: Verification.FailsIlVerify_UnrecognizedArgDelegate); +B", verify: Verification.FailsIlVerify); compilation.VerifyIL("C.M", @"{ // Code size 112 (0x70) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index 3a3f6aa331ca5..66de5e004d241 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -6073,7 +6073,7 @@ class A {} }); // ILVerify: Assembly or module not found: ErrTestMod02 - CompileAndVerify(comp, verify: Verification.FailsIlVerify_MissingAssembly).VerifyDiagnostics(); + CompileAndVerify(comp, verify: Verification.FailsIlVerify).VerifyDiagnostics(); } [Fact()] diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index 74a94b37a4d60..f759fedb0d4cf 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -23,50 +23,15 @@ namespace Microsoft.CodeAnalysis.Test.Utilities { - /// - /// Either verification is: - /// - Skipped - /// - Passes - /// - Fails (with breakdown of specific failures) - /// [Flags] public enum Verification { Skipped = 0, - Passes = 1 << 2, - Fails = FailsPeVerify_UnspecifiedError | FailsIlVerify_UnspecifiedError, - - // Don't use these directly - FailsPeVerify = 1 << 3, - FailsIlVerify = 1 << 4, - - // ILVerify errors - FailsIlVerify_UnspecifiedError = FailsIlVerify | 1 << 5, - FailsIlVerify_TypedReference = FailsIlVerify | 1 << 6, // ILVerify doesn't support TypedReference - FailsIlVerify_NotImplemented = FailsIlVerify | 1 << 7, // ILVerify has some un-implemented cases in EcmaModule.GetType - FailsIlVerify_NotVisible = FailsIlVerify | 1 << 8, // ILVerify: Type|Method|Field is not visible. - FailsIlVerify_UnrecognizedArgDelegate = FailsIlVerify | 1 << 9, // ILVerify: Unrecognized arguments for delegate .ctor. - FailsIlVerify_MissingStringType = FailsIlVerify | 1 << 10, // ILVerify: Internal.TypeSystem.TypeSystemException+TypeLoadException : Failed to load type 'System.String' from assembly ... - FailsIlVerify_MissingAssembly = FailsIlVerify | 1 << 11, // ILVerify: Assembly or module not found: ... - FailsIlVerify_UnexpectedReadonlyAddressOnStack = FailsIlVerify | 1 << 12, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } - FailsIlVerify_BadReturnType = FailsIlVerify | 1 << 13, // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. - FailsIlVerify_UnexpectedTypeOnStack = FailsIlVerify | 1 << 14, // ILVerify: Unexpected type on the stack. { Found = readonly address of ..., Expected = address of ... } - FailsIlVerify_ReturnFromCtor = FailsIlVerify | 1 << 15, // ILVerify: ImportCalli not implemented - FailsIlVerify_BadImage = FailsIlVerify | 1 << 16, // ILVerify: The format of a DLL or executable being loaded is invalid - - // Both - Fails_InitOnly = FailsPeVerify | FailsIlVerify | 1 << 17, // Cannot change initonly field outside its .ctor. - - // PEVerify errors - FailsPeVerify_UnspecifiedError = FailsIlVerify | 1 << 18, - FailsPeVerify_TypeLoadFailed = FailsPeVerify | 1 << 19, // ILVerify doesn't complain type load failed - FailsPeVerify_UnexpectedTypeOnStack = FailsPeVerify | 1 << 20, // ILVerify doesn't complain about: Unexpected type on the stack. - FailsPeVerify_UnableToResolveToken = FailsPeVerify | 1 << 21, // ILVerify doesn't complain about "unable to resolve token" - FailsPeVerify_TypeDevNotNil = FailsPeVerify | 1 << 22, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. - FailsPeVerify_ClassLayout = FailsPeVerify | 1 << 23, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. - FailsPeVerify_BadName = FailsPeVerify | 1 << 24, // PEVerify complains about: Assembly name contains leading spaces or path or extension. - FailsPeVerify_BadFormat = FailsPeVerify | 1 << 25, // TODO2 // PEVerify complains about: An attempt was made to load a program with an incorrect format. - FailsPeVerify_MissingManifest = FailsPeVerify | 1 << 26, // PEVerify complains about: The module was expected to contain an assembly manifest. + Passes = 1 << 1, + + FailsPeVerify = 1 << 2, + FailsIlVerify = 1 << 3, + Fails = FailsPeVerify | FailsIlVerify, } /// diff --git a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj index 3eda13903b3b0..7027dcf3bf103 100644 --- a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj +++ b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj @@ -106,7 +106,7 @@ - + diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index ceb5d818f9ae8..b3c2f05fad976 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -142,7 +142,6 @@ public void Verify(Verification verification) { var emitData = GetEmitData(); emitData.RuntimeData.PeverifyRequested = true; - // TODO(https://github.com/dotnet/coreclr/issues/295): Implement peverify // IL Verify if (verification == Verification.Skipped) @@ -168,21 +167,7 @@ public void Verify(Verification verification) var metadataReader = resolver.Resolve(name).GetMetadataReader(); if (metadataReader.AssemblyReferences.Count == 0) { - try - { - verifier.SetSystemModuleName(new AssemblyName(name)); - } - catch (Exception ex) - { - // ILVerify checks that corlib contains certain types - if ((verification & Verification.FailsIlVerify_MissingStringType) == Verification.FailsIlVerify_MissingStringType - && ex.Message.Contains("Failed to load type 'System.String' from assembly")) - { - return; - } - - throw; - } + verifier.SetSystemModuleName(new AssemblyName(name)); } } } @@ -198,85 +183,17 @@ public void Verify(Verification verification) throw new Exception("IL Verify succeeded unexpectedly"); } - string message = printVerificationResult(result); - if ((verification & Verification.FailsIlVerify_TypedReference) == Verification.FailsIlVerify_TypedReference - && message.Contains("TypedReference not supported in .NET Core")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_NotImplemented) == Verification.FailsIlVerify_NotImplemented - && message.Contains("The method or operation is not implemented.")) - { - return; - } - - if ((verification & Verification.Fails_InitOnly) == Verification.Fails_InitOnly - && message.Contains("Cannot change initonly field outside its .ctor.")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_NotVisible) == Verification.FailsIlVerify_NotVisible - && message.Contains(" is not visible.")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_UnrecognizedArgDelegate) == Verification.FailsIlVerify_UnrecognizedArgDelegate - && message.Contains("Unrecognized arguments for delegate .ctor.")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_MissingAssembly) == Verification.FailsIlVerify_MissingAssembly - && message.Contains("Assembly or module not found: ")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack) == Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack - && message.Contains("Unexpected type on the stack.") - && message.Contains("Found = readonly address of") - && message.Contains("Expected = address of")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_BadReturnType) == Verification.FailsIlVerify_BadReturnType - && message.Contains("Return type is ByRef, TypedReference, ArgHandle, or ArgIterator.")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_UnexpectedTypeOnStack) == Verification.FailsIlVerify_UnexpectedTypeOnStack - && message.Contains("Unexpected type on the stack.")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_ReturnFromCtor) == Verification.FailsIlVerify_ReturnFromCtor - && message.Contains("Return from .ctor when this is uninitialized.")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_UnspecifiedError) == Verification.FailsIlVerify_UnspecifiedError) + if ((verification & Verification.FailsIlVerify) != 0) { return; } + string message = printVerificationResult(result); throw new Exception("IL Verify failed unexpectedly: \r\n" + message); } - catch (Exception ex) + catch (Exception) { - if ((verification & Verification.FailsIlVerify_BadImage) == Verification.FailsIlVerify_BadImage - && ex.Message.Contains("The format of a DLL or executable being loaded is invalid")) - { - return; - } - - if ((verification & Verification.FailsIlVerify_UnspecifiedError) == Verification.FailsIlVerify_UnspecifiedError) + if ((verification & Verification.FailsIlVerify) != 0) { return; } diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index cd34fd84cfea6..ba8573405802e 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -320,55 +320,7 @@ public void Verify(Verification verification) } catch (RuntimePeVerifyException ex) { - if ((verification & Verification.FailsPeVerify_TypeLoadFailed) == Verification.FailsPeVerify_TypeLoadFailed - && ex.Message.Contains("Type load failed.")) - { - return; - } - - if ((verification & Verification.FailsPeVerify_UnexpectedTypeOnStack) == Verification.FailsPeVerify_UnexpectedTypeOnStack - && ex.Message.Contains("Unexpected type on the stack.")) - { - return; - } - - if ((verification & Verification.FailsPeVerify_UnableToResolveToken) == Verification.FailsPeVerify_UnableToResolveToken - && ex.Message.Contains("Unable to resolve token.")) - { - return; - } - - if ((verification & Verification.FailsPeVerify_TypeDevNotNil) == Verification.FailsPeVerify_TypeDevNotNil - && ex.Message.Contains("which is not nil.")) - { - return; - } - - if ((verification & Verification.FailsPeVerify_ClassLayout) == Verification.FailsPeVerify_ClassLayout - && ex.Message.Contains("marked AutoLayout.")) - { - return; - } - - if ((verification & Verification.FailsPeVerify_BadName) == Verification.FailsPeVerify_BadName - && ex.Message.Contains("Assembly name contains leading spaces or path or extension.")) - { - return; - } - - if ((verification & Verification.FailsPeVerify_MissingManifest) == Verification.FailsPeVerify_MissingManifest - && ex.Message.Contains("was expected to contain an assembly manifest.")) - { - return; - } - - if ((verification & Verification.Fails_InitOnly) == Verification.Fails_InitOnly - && ex.Message.Contains("Cannot change initonly field outside its .ctor.")) - { - return; - } - - if ((verification & Verification.FailsPeVerify_UnspecifiedError) == Verification.FailsPeVerify_UnspecifiedError) + if ((verification & Verification.FailsPeVerify) != 0) { return; } diff --git a/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb b/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb index ba00e3c160777..7562e21cb0a4e 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb @@ -767,7 +767,7 @@ end class ' ILVerify: Assembly or module not found: hash_module CompileAndVerify(compilation, manifestResources:=hash_resources, - verify:=Verification.FailsIlVerify_MissingAssembly, + verify:=Verification.FailsIlVerify, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -798,7 +798,7 @@ end class CompileAndVerify(compilation, manifestResources:=hash_resources, - verify:=Verification.FailsIlVerify_MissingAssembly, + verify:=Verification.FailsIlVerify, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -829,7 +829,7 @@ end class CompileAndVerify(compilation, manifestResources:=hash_resources, - verify:=Verification.FailsIlVerify_MissingAssembly, + verify:=Verification.FailsIlVerify, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -860,7 +860,7 @@ end class CompileAndVerify(compilation, manifestResources:=hash_resources, - verify:=Verification.FailsIlVerify_MissingAssembly, + verify:=Verification.FailsIlVerify, validator:=Sub(peAssembly) Dim reader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = reader.GetAssemblyDefinition() @@ -999,7 +999,7 @@ end class , options:=TestOptions.ReleaseDll, references:={hash_module_Comp.EmitToImageReference()}) CompileAndVerify(compilation, - verify:=Verification.FailsIlVerify_MissingAssembly, + verify:=Verification.FailsIlVerify, validator:=Sub(peAssembly) Dim metadataReader = peAssembly.ManifestModule.GetMetadataReader() Dim assembly As AssemblyDefinition = metadataReader.GetAssemblyDefinition() diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb index 62bb09bd16e88..48f20ee3da727 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb @@ -2437,7 +2437,7 @@ End Class , expectedOutput:=, verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack).VerifyIL("C2.DoStuff", , verify:=Verification.FailsIlVerify).VerifyIL("C2.DoStuff", -, verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack). +, verify:=Verification.FailsIlVerify). VerifyIL("Program.M", -, verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack). +, verify:=Verification.FailsIlVerify). VerifyIL("Program.M", diff --git a/src/Compilers/VisualBasic/Test/Emit/Emit/EmitMetadata.vb b/src/Compilers/VisualBasic/Test/Emit/Emit/EmitMetadata.vb index 2b40379f5a96a..d4cacff93f986 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Emit/EmitMetadata.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Emit/EmitMetadata.vb @@ -270,7 +270,7 @@ End Class TestOptions.ReleaseDll) ' ILVerify: The method or operation is not implemented. - dllImage = CompileAndVerify(c2, verify:=Verification.FailsIlVerify_UnspecifiedError).EmittedAssemblyData + dllImage = CompileAndVerify(c2, verify:=Verification.FailsIlVerify).EmittedAssemblyData Using metadata = AssemblyMetadata.CreateFromImage(dllImage) Dim emitAssemblyRefs2 As PEAssembly = metadata.GetAssembly @@ -309,7 +309,7 @@ End Class Assert.Equal(1, class1.Count()) ' ILVerify: Assembly or module not found: netModule1 - Dim manifestModule = CompileAndVerify(c1, verify:=Verification.FailsIlVerify_MissingAssembly).EmittedAssemblyData + Dim manifestModule = CompileAndVerify(c1, verify:=Verification.FailsIlVerify).EmittedAssemblyData Using metadata = AssemblyMetadata.Create(ModuleMetadata.CreateFromImage(manifestModule), netModule1, netModule2) Dim emitAddModule As PEAssembly = metadata.GetAssembly diff --git a/src/Compilers/VisualBasic/Test/Semantic/Compilation/CompilationAPITests.vb b/src/Compilers/VisualBasic/Test/Semantic/Compilation/CompilationAPITests.vb index e3a9f4e13a217..85eae7e8e04c4 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Compilation/CompilationAPITests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Compilation/CompilationAPITests.vb @@ -904,7 +904,7 @@ End Class assembly.VerifyDiagnostics() ' ILVerify: Assembly or module not found: missing2 - CompileAndVerify(assembly, verify:=Verification.FailsIlVerify_MissingAssembly) + CompileAndVerify(assembly, verify:=Verification.FailsIlVerify) End Sub diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb index 2cc703489d531..3bffbf42dc2ad 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/ConditionalAccessTests.vb @@ -4061,7 +4061,7 @@ C1 Ext4 C1 --------- -]]>, verify:=Verification.FailsIlVerify_UnexpectedReadonlyAddressOnStack) +]]>, verify:=Verification.FailsIlVerify) End Sub diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb index d58c8051a7f97..35d0665c6aedd 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/IReadOnlyListAndCollection.vb @@ -133,7 +133,7 @@ ProcessReadOnlyList3 ProcessReadOnlyList3 ProcessReadOnlyList3 ProcessReadOnlyListOfObject3 -]]>, verify:=Verification.FailsIlVerify_UnexpectedTypeOnStack) +]]>, verify:=Verification.FailsIlVerify) End Sub @@ -349,7 +349,7 @@ ProcessReadOnlyCollection3 ProcessReadOnlyCollection3 ProcessReadOnlyCollection3 ProcessReadOnlyCollectionOfObject3 -]]>, verify:=Verification.FailsIlVerify_UnexpectedTypeOnStack) +]]>, verify:=Verification.FailsIlVerify) End Sub From d57946ee45638baf885da6e2203c4452a28ff110 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Wed, 5 Jan 2022 11:40:41 -0800 Subject: [PATCH 28/51] Move check --- .../Test/Core/CompilationVerifier.cs | 129 ++++++++++++++++++ .../CoreClr/CoreCLRRuntimeEnvironment.cs | 110 --------------- 2 files changed, 129 insertions(+), 110 deletions(-) diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index 1ed62d8b828c8..c1a483266a978 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -19,6 +19,10 @@ using Microsoft.DiaSymReader.Tools; using Roslyn.Test.Utilities; using Xunit; +using System.Reflection.PortableExecutable; +using System.Reflection; +using System.Reflection.Metadata; +using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.Test.Utilities { @@ -203,6 +207,9 @@ public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions); _allModuleData = testEnvironment.GetAllModuleData(); testEnvironment.Verify(peVerify); +#if NETCOREAPP + ILVerify(peVerify); +#endif if (expectedSignatures != null) { @@ -220,6 +227,128 @@ public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, } } + private class Resolver : ILVerify.ResolverBase + { + private readonly Dictionary> imagesByName = new Dictionary>(); + + internal Resolver(IList allModuleData) + { + foreach (var module in allModuleData) + { + string name = module.FullName; + var image = module.Image; + + // TODO2 figure out why we need both the simple name and full name + imagesByName.Add(name, image); + if (module.SimpleName != name) + { + imagesByName.Add(module.SimpleName, image); + } + } + } + + protected override PEReader ResolveCore(string name) + { + if (imagesByName.TryGetValue(name, out var image)) + { + return new PEReader(image); + } + + return null; + } + } + + private void ILVerify(Verification verification) + { + if (verification == Verification.Skipped) + { + return; + } + + try + { + var resolver = new Resolver(_allModuleData); + var verifier = new ILVerify.Verifier(resolver); + var mscorlibModules = _allModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); + if (mscorlibModules.Length == 1) + { + verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); + } + else + { + // auto-detect which module is the "corlib" + foreach (var module in _allModuleData) + { + var name = module.SimpleName; + var metadataReader = resolver.Resolve(name).GetMetadataReader(); + if (metadataReader.AssemblyReferences.Count == 0) + { + verifier.SetSystemModuleName(new AssemblyName(name)); + } + } + } + + // Main module is the first one + var result = verifier.Verify(resolver.Resolve(_allModuleData[0].FullName)); + if (result.Count() == 0) + { + if ((verification & Verification.FailsIlVerify) == 0) + { + return; + } + + throw new Exception("IL Verify succeeded unexpectedly"); + } + + if ((verification & Verification.FailsIlVerify) != 0) + { + return; + } + + string message = printVerificationResult(result); + throw new Exception("IL Verify failed unexpectedly: \r\n" + message); + } + catch (Exception) + { + if ((verification & Verification.FailsIlVerify) != 0) + { + return; + } + + throw; + } + + static string printVerificationResult(IEnumerable result) + { + return string.Join("\r\n", result.Select(r => r.Message + printErrorArguments(r.ErrorArguments))); + } + + static string printErrorArguments(ILVerify.ErrorArgument[] errorArguments) + { + if (errorArguments is null + || errorArguments.Length == 0) + { + return ""; + } + + var pooledBuilder = PooledStringBuilder.GetInstance(); + var builder = pooledBuilder.Builder; + builder.Append(" { "); + var x = errorArguments.Select(a => a.Name + " = " + a.Value.ToString()).ToArray(); + for (int i = 0; i < x.Length; i++) + { + if (i > 0) + { + builder.Append(", "); + } + builder.Append(x[i]); + } + builder.Append(" }"); + + return pooledBuilder.ToStringAndFree(); + } + } + // TODO(tomat): Fold into CompileAndVerify. // Replace bool verify parameter with string[] expectedPeVerifyOutput. If null, no verification. If empty verify have to succeed. Otherwise compare errors. public void EmitAndVerify(params string[] expectedPeVerifyOutput) diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index b3c2f05fad976..70da322483d14 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -110,118 +110,8 @@ public int Execute(string moduleName, string[] args, string expectedOutput) public SortedSet GetMemberSignaturesFromMetadata(string fullyQualifiedTypeName, string memberName) => GetEmitData().GetMemberSignaturesFromMetadata(fullyQualifiedTypeName, memberName); - private class Resolver : ILVerify.ResolverBase - { - private readonly Dictionary> imagesByName = new Dictionary>(); - - internal Resolver(EmitData emitData) - { - foreach (var module in emitData.AllModuleData) - { - string name = module.FullName; - var image = module.Image; - - // TODO2 figure out why we need both the simple name and full name - imagesByName.Add(name, image); - imagesByName.TryAdd(module.SimpleName, image); - } - } - - protected override PEReader ResolveCore(string name) - { - if (imagesByName.TryGetValue(name, out var image)) - { - return new PEReader(image); - } - - return null; - } - } - public void Verify(Verification verification) { - var emitData = GetEmitData(); - emitData.RuntimeData.PeverifyRequested = true; - - // IL Verify - if (verification == Verification.Skipped) - { - return; - } - - try - { - var resolver = new Resolver(emitData); - var verifier = new ILVerify.Verifier(resolver); - var mscorlibModules = emitData.AllModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); - if (mscorlibModules.Length == 1) - { - verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); - } - else - { - // auto-detect which module is the "corlib" - foreach (var module in emitData.AllModuleData) - { - var name = module.SimpleName; - var metadataReader = resolver.Resolve(name).GetMetadataReader(); - if (metadataReader.AssemblyReferences.Count == 0) - { - verifier.SetSystemModuleName(new AssemblyName(name)); - } - } - } - - var result = verifier.Verify(resolver.Resolve(emitData.MainModule.FullName)); - if (result.Count() == 0) - { - if ((verification & Verification.FailsIlVerify) == 0) - { - return; - } - - throw new Exception("IL Verify succeeded unexpectedly"); - } - - if ((verification & Verification.FailsIlVerify) != 0) - { - return; - } - - string message = printVerificationResult(result); - throw new Exception("IL Verify failed unexpectedly: \r\n" + message); - } - catch (Exception) - { - if ((verification & Verification.FailsIlVerify) != 0) - { - return; - } - - throw; - } - - static string printVerificationResult(IEnumerable result) - { - return string.Join("\r\n", result.Select(r => r.Message + printErrorArguments(r.ErrorArguments))); - } - - static string printErrorArguments(ILVerify.ErrorArgument[] errorArguments) - { - if (errorArguments is null - || errorArguments.Length == 0) - { - return ""; - } - - var pooledBuilder = PooledStringBuilder.GetInstance(); - var builder = pooledBuilder.Builder; - builder.Append(" { "); - builder.AppendJoin(", ", errorArguments.Select(a => a.Name + " = " + a.Value.ToString())); - builder.Append(" }"); - - return pooledBuilder.ToStringAndFree(); - } } public string[] VerifyModules(string[] modulesToVerify) From a345b1b0d074901f8299007d3ee24854125b4896 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Wed, 5 Jan 2022 11:54:23 -0800 Subject: [PATCH 29/51] VB --- .../Test/Emit/CodeGen/CodeGenTryCatchThrow.vb | 2 +- .../VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb | 11 +++++++---- .../Test/Emit/Emit/CompilationEmitTests.vb | 3 ++- .../Emit/EditAndContinue/AssemblyReferencesTests.vb | 3 +-- src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb | 3 +-- .../VisualBasic/Test/Emit/XmlLiteralTests.vb | 3 ++- .../DefaultInterfaceImplementationTests.vb | 4 ++-- .../Symbol/SymbolsTests/ExtensionMethods/AddressOf.vb | 5 ++++- .../Symbol/SymbolsTests/Metadata/WinMdEventTest.vb | 7 +++++-- .../Test/Symbol/SymbolsTests/Retargeting/NoPia.vb | 3 ++- .../VisualBasic/Test/Symbol/UsedAssembliesTests.vb | 7 ++++--- 11 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTryCatchThrow.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTryCatchThrow.vb index f04a4fde7a2e7..2b223e9c97d04 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTryCatchThrow.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTryCatchThrow.vb @@ -121,7 +121,7 @@ L2: End Module , -verify:=Verification.Passes, ' TODO2 +verify:=Verification.FailsIlVerify, expectedOutput:="TryGoToCatchFinally"). VerifyIL("EmitTest.Main", -, references:={ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef_v46}, expectedOutput:=) +, references:={ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef_v46}, expectedOutput:=, verify:=Verification.FailsIlVerify) verifier.VerifyDiagnostics() verifier.VerifyIL("C.VB$StateMachine_2_Test(Of SM$T).MoveNext()", -, references:={ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef_v46}, expectedOutput:=) +, references:={ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef_v46}, expectedOutput:=, verify:=Verification.FailsIlVerify) verifier.VerifyDiagnostics() verifier.VerifyIL("C.VB$StateMachine_2_Test(Of SM$T).MoveNext()", Public Sub LongTupleWithSubstitution() - + ' ILVerify: + ' Failed to load type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' + ' Failed to load type 'System.Runtime.CompilerServices.YieldAwaitable' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' + ' Failed to load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Dim verifier = CompileAndVerify( @@ -5296,7 +5299,7 @@ Class C End Function End Class -, references:={ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef_v46}, expectedOutput:=) +, references:={ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef_v46}, expectedOutput:=, verify:=Verification.FailsIlVerify) verifier.VerifyDiagnostics() diff --git a/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb b/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb index 94c15d18c4598..fd2b9318efbe4 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Emit/CompilationEmitTests.vb @@ -402,7 +402,8 @@ End Class" Dim comp = CreateEmptyCompilation({Parse("")}) comp.MakeMemberMissing(WellKnownMember.System_Runtime_CompilerServices_ReferenceAssemblyAttribute__ctor) - CompileAndVerify(comp, emitOptions:=emitRefAssembly, verify:=Verification.Passes, validator:=assemblyValidator) + ' ILVerify: Failed to load type 'System.String' from assembly ... + CompileAndVerify(comp, emitOptions:=emitRefAssembly, verify:=Verification.FailsIlVerify, validator:=assemblyValidator) End Sub diff --git a/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.vb b/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.vb index 960c3a450a137..2dd296978e303 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.vb @@ -329,9 +329,8 @@ End Class Dim compilation0 = CreateCompilationWithMscorlib40({src0}, {ref01, ref11}, assemblyName:="C", options:=TestOptions.DebugDll) Dim compilation1 = compilation0.WithSource(src1).WithReferences({MscorlibRef, ref02, ref12}) - ' TODO2 ' ILVerify: Failed to load type 'D1' from assembly 'Lib, Version=1.0.0.1, Culture=neutral, PublicKeyToken=ce65828c82a341f2' - Dim v0 = CompileAndVerify(compilation0) + Dim v0 = CompileAndVerify(compilation0, verify:=Verification.FailsIlVerify) Dim f0 = compilation0.GetMember(Of MethodSymbol)("C.F") Dim f1 = compilation1.GetMember(Of MethodSymbol)("C.F") diff --git a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb index 9eb9f58256213..90b6e2a5a5e52 100644 --- a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb @@ -691,9 +691,8 @@ End Module - ' TODO2 ' ILVerify: Leave into try block. { Offset = 75 } - Dim v = CompileAndVerify(CreateCompilationWithMscorlib40AndVBRuntime(source, TestOptions.DebugExe)) + Dim v = CompileAndVerify(CreateCompilationWithMscorlib40AndVBRuntime(source, TestOptions.DebugExe), verify:=Verification.FailsIlVerify) v.VerifyIL("M1.Main", " { diff --git a/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb b/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb index d2bbd49cced0c..96c1f33a6fc05 100644 --- a/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/XmlLiteralTests.vb @@ -6,6 +6,7 @@ Imports System.IO Imports System.Text Imports Microsoft.Cci Imports Microsoft.CodeAnalysis.PooledObjects +Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Roslyn.Test.Utilities @@ -2968,7 +2969,7 @@ Module M End Sub End Module ]]> -, references:=Net40XmlReferences) +, references:=Net40XmlReferences, verify:=Verification.FailsIlVerify) compilation.VerifyIL("M.M(Of T)", CompileAndVerify(compilationDef, + verify:=Verification.FailsIlVerify, expectedOutput:= CompileAndVerify(compilationDef, + verify:=Verification.FailsIlVerify, expectedOutput:= - + ' ILVerify: Unrecognized arguments for delegate .ctor. { Offset = 8 } CompileAndVerify(compilationDef, + verify:=Verification.FailsIlVerify, expectedOutput:= - CompileAndVerify(compilation).VerifyIL("abcdef.goo", expectedIL.Value()) + ' ILVerify: Missing method 'System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken Windows.UI.Xaml.Application.add_Suspending(Windows.UI.Xaml.SuspendingEventHandler)' + CompileAndVerify(compilation, verify:=Verification.FailsIlVerify).VerifyIL("abcdef.goo", expectedIL.Value()) End Sub diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb index 9d416fc9e17f5..434cd74f616be 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb @@ -1633,7 +1633,8 @@ End Class references:={New VisualBasicCompilationReference(multiModule), New VisualBasicCompilationReference(pia1)}) - CompileAndVerify(consumer) + ' ILVerify: The method or operation is not implemented. + CompileAndVerify(consumer, verify:=Verification.FailsIlVerify) End Sub diff --git a/src/Compilers/VisualBasic/Test/Symbol/UsedAssembliesTests.vb b/src/Compilers/VisualBasic/Test/Symbol/UsedAssembliesTests.vb index 91f9706dc4e0b..29244b872cbf0 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/UsedAssembliesTests.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/UsedAssembliesTests.vb @@ -26,7 +26,8 @@ End Interface Dim comp1 = CreateEmptyCompilation(source) - CompileAndVerify(comp1) + ' ILVerify: Failed to load type 'System.String' from assembly ... + CompileAndVerify(comp1, verify:=Verification.FailsIlVerify) Assert.Empty(comp1.GetUsedAssemblyReferences()) @@ -48,7 +49,7 @@ End Interface Dim comp1 = CreateEmptyCompilation(source) - CompileAndVerify(comp1) + CompileAndVerify(comp1, verify:=Verification.FailsIlVerify) Dim source2 = @@ -235,7 +236,7 @@ End Interface Dim comp1 = CreateEmptyCompilation(source) - CompileAndVerify(comp1) + CompileAndVerify(comp1, verify:=Verification.FailsIlVerify) Dim source2 = From 7abba2eb0341d2ccf42bfe2dcdcbce7064a79b31 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Wed, 5 Jan 2022 13:02:40 -0800 Subject: [PATCH 30/51] Undo some changes --- .../Attributes/AttributeTests_IsByRefLike.cs | 1 + .../Attributes/AttributeTests_IsUnmanaged.cs | 2 ++ .../Attributes/AttributeTests_RefReadOnly.cs | 1 + .../InternalsVisibleToAndStrongNameTests.cs | 1 + .../Test/Emit/CodeGen/CodeGenAsyncEHTests.cs | 2 +- .../Emit/CodeGen/CodeGenAsyncSpillTests.cs | 6 +++--- .../Emit/CodeGen/CodeGenStructsAndEnum.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 1 - .../AssemblyReferencesTests.cs | 2 +- .../CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs | 6 +++--- .../Test/Core/CompilationVerifier.cs | 2 +- .../Desktop/DesktopRuntimeEnvironment.cs | 20 ++++++++++--------- 12 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index 7ed608705a040..d020c19a854ae 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -430,6 +430,7 @@ public class Test { public ref struct S1{} }"; + CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs index 34ffeecc7e81f..7030e4225e882 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs @@ -255,6 +255,7 @@ public class Test public void M() where T : unmanaged { } } "; + CompileAndVerify(text, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test").GetMethod("M").TypeParameters.Single(); @@ -280,6 +281,7 @@ public class Test where T : unmanaged { } "; + CompileAndVerify(text, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var typeParameter = module.ContainingAssembly.GetTypeByMetadataName("Test`1").TypeParameters.Single(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs index 0ac1eb31cb9a9..137fbe18116c7 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_RefReadOnly.cs @@ -1152,6 +1152,7 @@ public class Test { public void M(in int x) { } }"; + CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { AssertNoIsReadOnlyAttributeExists(module.ContainingAssembly); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index b25ca9823064a..cc8df3c8f7b05 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2722,6 +2722,7 @@ static void Main() System.Console.Write(A.I); } }"; + var ca = CreateCompilation(sourceA, options: TestOptions.ReleaseDll, assemblyName: "ClassLibrary2", parseOptions: parseOptions); CompileAndVerify(ca); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs index a3d51f3d389e2..c78a10b5218be 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs @@ -1841,7 +1841,7 @@ public static void Main() hello 2 "; - CompileAndVerify(source, expectedOutput: expected, verify: Verification.Passes); + CompileAndVerify(source, expectedOutput: expected); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs index f63f58685ac9d..30b1c5292d027 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs @@ -20,9 +20,9 @@ public CodeGenAsyncSpillTests() { } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null) { - return base.CompileAndVerify(source, expectedOutput: expectedOutput, references: references, options: options, verify: verify); + return base.CompileAndVerify(source, expectedOutput: expectedOutput, references: references, options: options); } [Fact] @@ -2479,7 +2479,7 @@ public static void Main() 2 0 "; - CompileAndVerify(source, expectedOutput: expected, verify: Verification.Passes); + CompileAndVerify(source, expectedOutput: expected); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index ed70002e1d3c6..d3e17f30688ed 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -1283,7 +1283,7 @@ public static void Main() } "; - var compilation = CompileAndVerify(source, expectedOutput: "11", verify: Verification.Passes); + var compilation = CompileAndVerify(source, expectedOutput: "11"); compilation.VerifyIL("D.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 6d17a65434e5d..1045fa6197b65 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -13334,7 +13334,6 @@ private void PrintArgList(ArgIterator args) "; var compilation = CompileAndVerify( source, - verify: Verification.Passes, expectedOutput: @"Inside - TestVarArgs::ctor (__arglist) Inside - TestVarArgs::ctor (__arglist) System.Int32 diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs index efea9625ae66e..068ba6382dc68 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs @@ -481,7 +481,7 @@ class C var compilation0 = CreateEmptyCompilation(src0, new[] { MscorlibRef, ref01, ref11 }, assemblyName: "C", options: TestOptions.DebugDll); var compilation1 = compilation0.WithSource(src1).WithReferences(new[] { MscorlibRef, ref02, ref12 }); - var v0 = CompileAndVerify(compilation0, verify: Verification.Passes); + var v0 = CompileAndVerify(compilation0); var f0 = compilation0.GetMember("C.F"); var f1 = compilation1.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs index c9361d66153ff..12d02e257d8f9 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs @@ -1665,12 +1665,12 @@ .maxstack 2 } "; - var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.Passes); + var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); - verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.Passes); + verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); @@ -5407,7 +5407,7 @@ static string MyEvent02Handler(string arg) { var app_compilation = CreateCompilation(App_cs, new[] { NetImpl_ref, IEvent_ref, CSharpRef }, options: TestOptions.ReleaseExe, assemblyName: "App"); - CompileAndVerify(app_compilation, verify: Verification.Passes, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, + CompileAndVerify(app_compilation, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, expectedOutput: @"E01 E02"); } diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index c1a483266a978..88fabb7c7416c 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -207,7 +207,7 @@ public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions); _allModuleData = testEnvironment.GetAllModuleData(); testEnvironment.Verify(peVerify); -#if NETCOREAPP +#if NETCOREAPP // TODO2 need strong-named ILVerify ILVerify(peVerify); #endif diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index ba8573405802e..41df76ae1ffa3 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -299,33 +299,35 @@ public IList GetAllModuleData() public void Verify(Verification verification) { + // Verification is only done on windows desktop + if (!ExecutionConditionUtil.IsWindowsDesktop) + { + return; + } + if (verification == Verification.Skipped) { return; } + var shouldSucceed = (verification & Verification.FailsPeVerify) == 0; var emitData = GetEmitData(); - // PE Verify try { emitData.RuntimeData.PeverifyRequested = true; emitData.Manager.PeVerifyModules(new[] { emitData.MainModule.FullName }, throwOnError: true); - if ((verification & Verification.FailsPeVerify) == 0) + if (!shouldSucceed) { - return; + throw new Exception("PE Verify succeeded unexpectedly"); } - - throw new Exception("PE Verify succeeded unexpectedly"); } catch (RuntimePeVerifyException ex) { - if ((verification & Verification.FailsPeVerify) != 0) + if (shouldSucceed) { - return; + throw new Exception("Verification failed", ex); } - - throw new Exception("Verification failed", ex); } } From f3a385943bc009f6ba96609cffdd8297d43c1157 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Wed, 5 Jan 2022 13:46:36 -0800 Subject: [PATCH 31/51] Cleanup --- .../Attributes/AttributeTests_Assembly.cs | 6 +-- .../AttributeTests_ReadOnlyStruct.cs | 2 +- .../InternalsVisibleToAndStrongNameTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenAsyncEHTests.cs | 4 +- .../CSharp/Test/Emit/Emit/EmitErrorTests.cs | 9 ++-- .../DefaultInterfaceImplementationTests.cs | 42 +++++++++---------- .../Symbol/Symbols/ExtensionMethodTests.cs | 2 +- .../Test/Emit/CodeGen/CodeGenTests.vb | 5 ++- .../Emit/ExpressionTrees/CodeGenExprLambda.vb | 17 +++++--- 9 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 4d07412d081fc..70f94fd256f54 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -664,7 +664,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Skipped, + CompileAndVerify(compilation, verify: Verification.Fails, manifestResources: hash_resources, validator: (peAssembly) => { @@ -693,7 +693,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Skipped, + CompileAndVerify(compilation, verify: Verification.Fails, manifestResources: hash_resources, validator: (peAssembly) => { @@ -726,7 +726,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Skipped, + CompileAndVerify(compilation, verify: Verification.Fails, manifestResources: hash_resources, validator: (peAssembly) => { diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs index 75d4421cb78e4..2a148fe1f4794 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_ReadOnlyStruct.cs @@ -429,7 +429,7 @@ public readonly struct S1{} // PEVerify: The module was expected to contain an assembly manifest. // ILVerify: The format of a DLL or executable being loaded is invalid - CompileAndVerify(code, verify: Verification.Skipped, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => + CompileAndVerify(code, verify: Verification.Fails, references: new[] { reference }, options: TestOptions.ReleaseModule, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("Test").GetTypeMember("S1"); Assert.True(type.IsReadOnly); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index cc8df3c8f7b05..ba775a35557ac 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2727,7 +2727,7 @@ static void Main() CompileAndVerify(ca); var cb = CreateCompilation(sourceB, options: TestOptions.ReleaseExe, assemblyName: "X", references: new[] { new CSharpCompilationReference(ca) }, parseOptions: parseOptions); - CompileAndVerify(cb, expectedOutput: "42", verify: Verification.Passes).Diagnostics.Verify(); + CompileAndVerify(cb, expectedOutput: "42").Diagnostics.Verify(); } [WorkItem(1095618, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095618")] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs index c78a10b5218be..7d612c9e4f045 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs @@ -23,10 +23,10 @@ public CodeGenAsyncEHTests() { } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null) { references = (references != null) ? references.Concat(s_asyncRefs) : s_asyncRefs; - return base.CompileAndVerify(source, targetFramework: TargetFramework.Empty, expectedOutput: expectedOutput, references: references, options: options, verify: verify); + return base.CompileAndVerify(source, targetFramework: TargetFramework.Empty, expectedOutput: expectedOutput, references: references, options: options); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs index 37feb83a8de0e..aa1f4128b5f91 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs @@ -110,7 +110,8 @@ public static void Main() } } "; - // TODO2 ILVerify null ref + // ILVerify null ref + // Tracked by https://github.com/dotnet/roslyn/issues/58652 var compilation2 = CompileAndVerify( source2, new[] { new CSharpCompilationReference(compilation1) }, @@ -143,7 +144,8 @@ public static void Main() } } "; - // TODO2 ILVerify null ref + // ILVerify null ref + // Tracked by https://github.com/dotnet/roslyn/issues/58652 var compilation2 = CompileAndVerify( source2, new[] { new CSharpCompilationReference(compilation1) }, @@ -181,7 +183,8 @@ public static void Main() } "; - // TODO2 ILVerify null ref + // ILVerify null ref + // Tracked by https://github.com/dotnet/roslyn/issues/58652 var compilation2 = CompileAndVerify( source2, new[] { new CSharpCompilationReference(compilation1) }, diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs index aba60f5b301c9..5682ba9ca72b9 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs @@ -44,16 +44,14 @@ private static Verification VerifyOnMonoOrCoreClr { get { - // TODO2 return ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.Passes : Verification.Skipped; } } - private static Verification VerifyOnMonoOrCoreClr_Fails + private static Verification VerifyOnMonoOrCoreClr_FailsIlVerify { get { - // TODO2 return ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.FailsIlVerify : Verification.Skipped; } } @@ -9648,7 +9646,7 @@ static void Main() M2 M3", symbolValidator: validate, - verify: VerifyOnMonoOrCoreClr_Fails); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify); validate(compilation1.SourceModule); @@ -9712,7 +9710,7 @@ static void Main() CompileAndVerify(compilation4, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1 M2", - verify: VerifyOnMonoOrCoreClr_Fails); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -17964,7 +17962,7 @@ static void Main() get_P6 set_P6", symbolValidator: validate, - verify: VerifyOnMonoOrCoreClr_Fails); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify); validate(compilation1.SourceModule); @@ -18073,7 +18071,7 @@ static void Main() set_P5 set_P6 ", - verify: VerifyOnMonoOrCoreClr_Fails); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -28454,7 +28452,7 @@ static void Main() get_P2 set_P2 get_P3 -set_P3", symbolValidator: validate, verify: VerifyOnMonoOrCoreClr_Fails); +set_P3", symbolValidator: validate, verify: VerifyOnMonoOrCoreClr_FailsIlVerify); validate(compilation1.SourceModule); @@ -28527,7 +28525,7 @@ static void Main() set_P1 get_P2 set_P2", - verify: VerifyOnMonoOrCoreClr_Fails); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var compilation5 = CreateCompilation(source4, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29269,7 +29267,7 @@ public void M1() } "; - ValidateNestedTypes_01(source0 + source1, Accessibility.Protected, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_Fails); + ValidateNestedTypes_01(source0 + source1, Accessibility.Protected, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var compilation1 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular, @@ -29375,7 +29373,7 @@ public void M1() I1+T3 B I1+T5", - verify: VerifyOnMonoOrCoreClr_Fails); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var compilation5 = CreateCompilation(source2, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29510,7 +29508,7 @@ public void M1() I1+T3 B I1+T5", - verify: VerifyOnMonoOrCoreClr_Fails); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var compilation5 = CreateCompilation(source2, options: TestOptions.DebugExe, references: new[] { reference }, @@ -29819,7 +29817,7 @@ public void M1() } } "; - ValidateNestedTypes_01(source0 + source1, Accessibility.ProtectedAndInternal, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_Fails); + ValidateNestedTypes_01(source0 + source1, Accessibility.ProtectedAndInternal, targetFramework: TargetFramework.NetCoreApp, execute: ExecutionConditionUtil.IsMonoOrCoreClr, verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var compilation1 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular, @@ -32829,7 +32827,7 @@ static void Main() @"I2.M1 I4.M1 ", - verify: VerifyOnMonoOrCoreClr_Fails, + verify: VerifyOnMonoOrCoreClr_FailsIlVerify, symbolValidator: ValidateMethodImplementationInDerived_01); foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) @@ -33075,7 +33073,7 @@ static void Main() @"I2.M1 I4.M1 ", - verify: VerifyOnMonoOrCoreClr_Fails, + verify: VerifyOnMonoOrCoreClr_FailsIlVerify, symbolValidator: ValidateMethodImplementationInDerived_01); foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() }) @@ -38938,7 +38936,7 @@ public static void Test() @"123 -2 ", - verify: VerifyOnMonoOrCoreClr_Fails, symbolValidator: validate); + verify: VerifyOnMonoOrCoreClr_FailsIlVerify, symbolValidator: validate); var source2 = @" @@ -38960,7 +38958,7 @@ static void Main() parseOptions: TestOptions.Regular, targetFramework: TargetFramework.NetCoreApp); - CompileAndVerify(compilation2, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "1122" : null, verify: VerifyOnMonoOrCoreClr_Fails); + CompileAndVerify(compilation2, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "1122" : null, verify: VerifyOnMonoOrCoreClr_FailsIlVerify); } var source3 = @@ -44789,7 +44787,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var source2 = @" interface I2 : I3 @@ -44815,7 +44813,7 @@ static void Main() var compilation1 = CreateCompilation(source0 + source2, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation1.VerifyDiagnostics(); - CompileAndVerify(compilation1, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); + CompileAndVerify(compilation1, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var source3 = @" interface I2 : I3 @@ -44952,7 +44950,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_FailsIlVerify); var source3 = @" class I2 @@ -45012,7 +45010,7 @@ static void Main() var compilation0 = CreateCompilation(source0 + source1, options: TestOptions.DebugExe, targetFramework: TargetFramework.NetCoreApp); compilation0.VerifyDiagnostics(); - CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_Fails); + CompileAndVerify(compilation0, expectedOutput: !ExecutionConditionUtil.IsMonoOrCoreClr ? null : @"M1", verify: VerifyOnMonoOrCoreClr_FailsIlVerify); } private const string NoPiaAttributes = @" @@ -45472,7 +45470,7 @@ void ITest33.M1(){} var piaCompilation = CreateCompilation(pia, options: TestOptions.ReleaseDll, references: new[] { attributesRef }, targetFramework: TargetFramework.NetCoreApp); - // TODO2 ILVerify: Missing method 'Void UsePia.Test(ITest33)' + // ILVerify: Missing method 'Void UsePia.Test(ITest33)' CompileAndVerify(piaCompilation, verify: VerifyOnMonoOrCoreClr); string consumer1 = @" diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs index be69a949aaac3..5532b14246f0c 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs @@ -2293,7 +2293,7 @@ static void M(Action a) a(); } }"; - // TODO2 ILVerify: Unrecognized arguments for delegate .ctor. + // ILVerify: Unrecognized arguments for delegate .ctor. var compilation = CompileAndVerify(source, expectedOutput: @"F: System.Int32 F: S diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb index b6838f25e1508..b525afdfb0f9d 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb @@ -6063,7 +6063,8 @@ End Module Public Sub TestGetObjectValueCalls() - + ' ILVerify null ref + ' Tracked by https//github.com/dotnet/roslyn/issues/58652 Dim verifier = CompileAndVerify( @@ -6288,7 +6289,7 @@ Module Program1 End Module -, references:={TestReferences.SymbolsTests.PropertiesWithByRef}) +, references:={TestReferences.SymbolsTests.PropertiesWithByRef}, verify:=Verification.FailsIlVerify) verifier.VerifyIL("Module1.M", Public Sub ExprTree_LegacyTests02_v40() + ' ILVerify: Unrecognized arguments for delegate .ctor. { Offset = 1223 } Dim file = - TestExpressionTrees(file, ExpTreeTestResources.ExprTree_LegacyTests02_v40_Result) + TestExpressionTrees(file, ExpTreeTestResources.ExprTree_LegacyTests02_v40_Result, verify:=Verification.FailsIlVerify) End Sub Public Sub ExprTree_LegacyTests02_v45() + ' ILVerify: Unrecognized arguments for delegate .ctor. { Offset = 1167 } Dim file = - TestExpressionTrees(file, ExpTreeTestResources.ExprTree_LegacyTests02_v45_Result, latestReferences:=True) + TestExpressionTrees(file, ExpTreeTestResources.ExprTree_LegacyTests02_v45_Result, latestReferences:=True, verify:=Verification.FailsIlVerify) End Sub From 262ee1e071f70d71731ddd9aaccd520c3189bc46 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 6 Jan 2022 00:19:20 -0800 Subject: [PATCH 32/51] Refine resolution of ambiguities --- .../Test/Core/CompilationVerifier.cs | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index 88fabb7c7416c..c4499c0e1951b 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -233,16 +233,25 @@ private class Resolver : ILVerify.ResolverBase internal Resolver(IList allModuleData) { + foreach (var module in allModuleData) { - string name = module.FullName; var image = module.Image; + imagesByName.Add(module.FullName, image); - // TODO2 figure out why we need both the simple name and full name - imagesByName.Add(name, image); - if (module.SimpleName != name) + // Note: although the signature in ResolverBase.ResolveCore calls the parameter "simpleName" + // ILVerify can also pass in full names. So we do allow resolving both. + if (module.SimpleName != module.FullName) { - imagesByName.Add(module.SimpleName, image); + if (imagesByName.ContainsKey(module.SimpleName)) + { + imagesByName.Remove(module.SimpleName); + imagesByName.Add(module.SimpleName, default); + } + else + { + imagesByName.Add(module.SimpleName, image); + } } } } @@ -251,10 +260,14 @@ protected override PEReader ResolveCore(string name) { if (imagesByName.TryGetValue(name, out var image)) { + if (image.IsDefault) + { + throw new Exception($"ILVerify was not able to resolve a module named '{name}' because multiple exist in this compilation"); + } return new PEReader(image); } - return null; + throw new Exception($"ILVerify was not able to resolve a module named '{name}'"); } } @@ -276,14 +289,16 @@ private void ILVerify(Verification verification) } else { - // auto-detect which module is the "corlib" + // ILVerify requires a "system" module to be identified (see ILVerify.Verifier.ThrowMissingSystemModule) + // So we auto-detect a candidate module foreach (var module in _allModuleData) { - var name = module.SimpleName; + var name = module.FullName; var metadataReader = resolver.Resolve(name).GetMetadataReader(); if (metadataReader.AssemblyReferences.Count == 0) { verifier.SetSystemModuleName(new AssemblyName(name)); + break; } } } From 733ac37fe248f9cee1e1d4795af1e007e6dcaac0 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 6 Jan 2022 00:43:40 -0800 Subject: [PATCH 33/51] Align on simple names --- .../AssemblyReferencesTests.cs | 3 +- .../Test/Core/CompilationVerifier.cs | 35 +++++++------------ .../Retargeting/RetargetingTests.vb | 27 +++++++++----- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs index 068ba6382dc68..69727d8f49db4 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs @@ -481,7 +481,8 @@ class C var compilation0 = CreateEmptyCompilation(src0, new[] { MscorlibRef, ref01, ref11 }, assemblyName: "C", options: TestOptions.DebugDll); var compilation1 = compilation0.WithSource(src1).WithReferences(new[] { MscorlibRef, ref02, ref12 }); - var v0 = CompileAndVerify(compilation0); + // ILVerify: Multiple modules named 'Lib' were found + var v0 = CompileAndVerify(compilation0, verify: Verification.FailsIlVerify); var f0 = compilation0.GetMember("C.F"); var f1 = compilation1.GetMember("C.F"); diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index c4499c0e1951b..598021dcbb515 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -233,41 +233,29 @@ private class Resolver : ILVerify.ResolverBase internal Resolver(IList allModuleData) { - foreach (var module in allModuleData) { - var image = module.Image; - imagesByName.Add(module.FullName, image); - - // Note: although the signature in ResolverBase.ResolveCore calls the parameter "simpleName" - // ILVerify can also pass in full names. So we do allow resolving both. - if (module.SimpleName != module.FullName) + string name = module.SimpleName; + if (imagesByName.ContainsKey(module.SimpleName)) { - if (imagesByName.ContainsKey(module.SimpleName)) - { - imagesByName.Remove(module.SimpleName); - imagesByName.Add(module.SimpleName, default); - } - else - { - imagesByName.Add(module.SimpleName, image); - } + throw new Exception($"Multiple modules named '{name}' were found"); } + imagesByName.Add(name, module.Image); } } - protected override PEReader ResolveCore(string name) + protected override PEReader ResolveCore(string simpleName) { - if (imagesByName.TryGetValue(name, out var image)) + if (imagesByName.TryGetValue(simpleName, out var image)) { if (image.IsDefault) { - throw new Exception($"ILVerify was not able to resolve a module named '{name}' because multiple exist in this compilation"); + throw new Exception($"ILVerify was not able to resolve a module named '{simpleName}' because multiple exist in this compilation"); } return new PEReader(image); } - throw new Exception($"ILVerify was not able to resolve a module named '{name}'"); + throw new Exception($"ILVerify was not able to resolve a module named '{simpleName}'"); } } @@ -285,15 +273,16 @@ private void ILVerify(Verification verification) var mscorlibModules = _allModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); if (mscorlibModules.Length == 1) { - verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); + verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].SimpleName)); } else { // ILVerify requires a "system" module to be identified (see ILVerify.Verifier.ThrowMissingSystemModule) // So we auto-detect a candidate module + // This comes in handy in tests that use TestBase.AacorlibRef for instance. foreach (var module in _allModuleData) { - var name = module.FullName; + var name = module.SimpleName; var metadataReader = resolver.Resolve(name).GetMetadataReader(); if (metadataReader.AssemblyReferences.Count == 0) { @@ -304,7 +293,7 @@ private void ILVerify(Verification verification) } // Main module is the first one - var result = verifier.Verify(resolver.Resolve(_allModuleData[0].FullName)); + var result = verifier.Verify(resolver.Resolve(_allModuleData[0].SimpleName)); if (result.Count() == 0) { if ((verification & Verification.FailsIlVerify) == 0) diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/RetargetingTests.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/RetargetingTests.vb index b61ce12c60488..4c4581a465483 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/RetargetingTests.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/RetargetingTests.vb @@ -943,7 +943,8 @@ End Namespace 'Retargetted - should result in No additional Errors also and same runtime behavior Dim RetargetReference = RetargetCompilationToV2MsCorlib(referenceLibrary_Compilation) - Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, + ' ILVerify: Multiple modules named 'mscorlib' were found + Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, verify:=Verification.FailsIlVerify, expectedOutput:=) Main_Retarget.VerifyDiagnostics() @@ -1307,7 +1308,8 @@ End Namespace '//Retargetted - should result in No Errors also and same runtime behavior Dim RetargetReference = RetargetCompilationToV2MsCorlib(referenceLibrary_Compilation) - Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, + ' ILVerify: Multiple modules named 'mscorlib' were found + Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, verify:=Verification.FailsIlVerify, expectedOutput:=) Main_Retarget.VerifyDiagnostics() @@ -1693,7 +1695,8 @@ Imports System '//Retargetted - should result in No Errors also and same runtime behavior Dim RetargetReference = RetargetCompilationToV2MsCorlib(referenceLibrary_Compilation) - Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, + ' ILVerify: Multiple modules named 'mscorlib' were found + Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, verify:=Verification.FailsIlVerify, expectedOutput:=) '//Retargetted - should result in No Errors also and same runtime behavior Dim RetargetReference = RetargetCompilationToV2MsCorlib(referenceLibrary_Compilation) - Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, + ' ILVerify: Multiple modules named 'mscorlib' were found + Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, verify:=Verification.FailsIlVerify, expectedOutput:=) @@ -2681,12 +2687,14 @@ End Class ''//All on same FX - should result in No Errors Dim referenceLibrary_Compilation = DirectCast(CompileAndVerify(sourceLibV1, options:=TestOptions.ReleaseDll).Compilation, VisualBasicCompilation) - Dim main_NoRetarget = CompileAndVerify(sourceMain, references:={referenceLibrary_Compilation.ToMetadataReference}) + ' ILVerify: Multiple modules named 'mscorlib' were found + Dim main_NoRetarget = CompileAndVerify(sourceMain, references:={referenceLibrary_Compilation.ToMetadataReference}, verify:=Verification.FailsIlVerify) main_NoRetarget.VerifyDiagnostics() ''//Retargetted - should result in No Errors also Dim RetargetReference = RetargetCompilationToV2MsCorlib(referenceLibrary_Compilation) - Dim Main_Retarget = CompileAndVerify(sourceMain, references:={RetargetReference}, options:=TestOptions.ReleaseExe) + ' ILVerify: Multiple modules named 'mscorlib' were found + Dim Main_Retarget = CompileAndVerify(sourceMain, references:={RetargetReference}, options:=TestOptions.ReleaseExe, verify:=Verification.FailsIlVerify) main_NoRetarget.VerifyDiagnostics() End Sub @@ -3081,7 +3089,8 @@ End Namespace '//Retargetted - should result in No Errors also and same runtime behavior Dim RetargetReference = RetargetCompilationToV2MsCorlib(referenceLibrary_Compilation) - Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, + ' ILVerify: Multiple modules named 'mscorlib' were found + Dim Main_Retarget = CompileAndVerify(source, references:={RetargetReference}, options:=TestOptions.ReleaseExe, verify:=Verification.FailsIlVerify, expectedOutput:=) Main_Retarget.VerifyDiagnostics() From c1f0f8d4c97272dc43cd660e8676fb76e1b6c883 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Fri, 28 Jan 2022 22:03:28 -0800 Subject: [PATCH 34/51] Use signed ILVerification package from dotnet7 feed --- NuGet.config | 1 + .../Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 8c879770d5df4..513b93df1e591 100644 --- a/NuGet.config +++ b/NuGet.config @@ -7,6 +7,7 @@ + diff --git a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj index 7027dcf3bf103..0384176dff8a5 100644 --- a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj +++ b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj @@ -106,7 +106,7 @@ - + From f193504ac3d14cc89a25c9b123cb3eb1152bbaf3 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Fri, 28 Jan 2022 22:22:23 -0800 Subject: [PATCH 35/51] Enable on desktop runtime --- src/Compilers/Test/Core/CompilationVerifier.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index 598021dcbb515..f1f4770a694bd 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -207,9 +207,7 @@ public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions); _allModuleData = testEnvironment.GetAllModuleData(); testEnvironment.Verify(peVerify); -#if NETCOREAPP // TODO2 need strong-named ILVerify ILVerify(peVerify); -#endif if (expectedSignatures != null) { @@ -271,6 +269,7 @@ private void ILVerify(Verification verification) var resolver = new Resolver(_allModuleData); var verifier = new ILVerify.Verifier(resolver); var mscorlibModules = _allModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); + // TODO2 identify corlib in rigorous way if (mscorlibModules.Length == 1) { verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].SimpleName)); From 4cf0b498b77761d74f68d8c182e8c447534131a6 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 29 Jan 2022 10:33:23 -0800 Subject: [PATCH 36/51] Revert "Enable on desktop runtime" This reverts commit f193504ac3d14cc89a25c9b123cb3eb1152bbaf3. --- src/Compilers/Test/Core/CompilationVerifier.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index f1f4770a694bd..3d3d64f406c1e 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -207,7 +207,9 @@ public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions); _allModuleData = testEnvironment.GetAllModuleData(); testEnvironment.Verify(peVerify); +#if NETCOREAPP ILVerify(peVerify); +#endif if (expectedSignatures != null) { @@ -269,7 +271,6 @@ private void ILVerify(Verification verification) var resolver = new Resolver(_allModuleData); var verifier = new ILVerify.Verifier(resolver); var mscorlibModules = _allModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); - // TODO2 identify corlib in rigorous way if (mscorlibModules.Length == 1) { verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].SimpleName)); From dceda429e3f181c033132a17947a7b5fadce7784 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 29 Jan 2022 12:55:09 -0800 Subject: [PATCH 37/51] Update added tests --- .../Test/Emit2/Attributes/AttributeTests_Synthesized.cs | 2 +- .../CodeGen/CodeGenMethodGroupConversionCachingTests.cs | 7 +++++-- .../CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_Synthesized.cs index 2e4857c663560..dfdac6906bf24 100644 --- a/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_Synthesized.cs @@ -956,7 +956,7 @@ public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(Ou { // ILVerify: Failed to load type 'System.String' from assembly // ILVerify: The format of a DLL or executable being loaded is invalid - var verify = outputKind.IsNetModule() + var verify = outputKind.IsNetModule() ? Verification.Fails : Verification.FailsIlVerify; diff --git a/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenMethodGroupConversionCachingTests.cs b/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenMethodGroupConversionCachingTests.cs index 50cc12f67f61a..3933bcba5f981 100644 --- a/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenMethodGroupConversionCachingTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenMethodGroupConversionCachingTests.cs @@ -7,6 +7,7 @@ using System.Linq; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; +using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; @@ -146,7 +147,8 @@ static class E public static void Target(this C that) { Console.WriteLine(""FAIL""); } } "; - var verifier = CompileAndVerify(source, expectedOutput: PASS, symbolValidator: VerifyNoCacheContainersIn("C")); + // ILVerify: Unrecognized arguments for delegate .ctor. { Offset = 14 } + var verifier = CompileAndVerify(source, expectedOutput: PASS, symbolValidator: VerifyNoCacheContainersIn("C"), verify: Verification.FailsIlVerify); verifier.VerifyIL("C.Main", @" { // Code size 37 (0x25) @@ -188,7 +190,8 @@ static class E public static void Target(this C that) { Console.WriteLine(""FAIL""); } } "; - var verifier = CompileAndVerify(source, expectedOutput: PASS, symbolValidator: VerifyNoCacheContainersIn("C")); + // ILVerify: Unrecognized arguments for delegate .ctor. { Offset = 14 } + var verifier = CompileAndVerify(source, expectedOutput: PASS, symbolValidator: VerifyNoCacheContainersIn("C"), verify: Verification.FailsIlVerify); verifier.VerifyIL("C.Main", @" { // Code size 37 (0x25) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs index f58429f19dc13..54b7b585d09c2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs @@ -8491,12 +8491,13 @@ static void Main() var comp = CreateCompilation(source, options: TestOptions.ReleaseExe); comp.VerifyDiagnostics(); + // ILVerify: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. { Offset = 24 } CompileAndVerify(comp, expectedOutput: @"0 System.Object <>f__AnonymousDelegate0 <>f__AnonymousDelegate1 -"); +", verify: Verification.FailsIlVerify); } [Fact] From 115da8acaa38c39ca361ec498ab2337ba7b155a7 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sun, 30 Jan 2022 18:12:34 -0800 Subject: [PATCH 38/51] Use compilation to identify corlib --- .../Semantic/Semantics/UseSiteErrorTests.cs | 3 ++- .../Core/Compilation/IRuntimeEnvironment.cs | 23 +++++++++++------- .../Test/Core/CompilationVerifier.cs | 24 +++---------------- .../Test/Core/Metadata/ModuleData.cs | 10 +++++--- .../CoreClr/CoreCLRRuntimeEnvironment.cs | 7 ++++-- .../Desktop/DesktopRuntimeEnvironment.cs | 7 ++++-- .../Platform/Desktop/RuntimeModuleData.cs | 4 +++- .../Emit/Attributes/AssemblyAttributes.vb | 6 ++--- .../Semantic/Semantics/UseSiteErrorTests.vb | 3 ++- .../Symbol/SymbolsTests/Metadata/PE/NoPia.vb | 1 + 10 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs index eff9158c26ef9..d82fe22907247 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs @@ -2367,7 +2367,8 @@ interface I2 // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1) ); - CompileAndVerify(compilation5); + // ILVerify: no corlib + CompileAndVerify(compilation5, verify: Verification.FailsIlVerify); Assert.Equal(TypeKind.Struct, compilation5.GetTypeByMetadataName("A").TypeKind); Assert.Equal(TypeKind.Enum, compilation5.GetTypeByMetadataName("B").TypeKind); diff --git a/src/Compilers/Test/Core/Compilation/IRuntimeEnvironment.cs b/src/Compilers/Test/Core/Compilation/IRuntimeEnvironment.cs index faf86ba2a4501..caed5dec5680e 100644 --- a/src/Compilers/Test/Core/Compilation/IRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Compilation/IRuntimeEnvironment.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -91,7 +92,7 @@ private static IEnumerable EnumerateModules(Metadata metadata) /// /// Emit all of the references which are not directly or indirectly a value. /// - internal static void EmitReferences(Compilation compilation, HashSet fullNameSet, List dependencies, DiagnosticBag diagnostics) + internal static void EmitReferences(Compilation compilation, HashSet fullNameSet, List dependencies, DiagnosticBag diagnostics, AssemblyIdentity corLibIdentity) { // NOTE: specifically don't need to consider previous submissions since they will always be compilations. foreach (var metadataReference in compilation.References) @@ -115,6 +116,7 @@ internal static void EmitReferences(Compilation compilation, HashSet ful continue; } + var isCorLib = isManifestModule && corLibIdentity == identity; foreach (var module in EnumerateModules(metadata)) { ImmutableArray bytes = module.Module.PEReaderOpt.GetEntireImage().GetContent(); @@ -126,14 +128,16 @@ internal static void EmitReferences(Compilation compilation, HashSet ful OutputKind.DynamicallyLinkedLibrary, bytes, pdb: default(ImmutableArray), - inMemoryModule: true); + inMemoryModule: true, + isCorLib); } else { moduleData = new ModuleData(module.Name, bytes, pdb: default(ImmutableArray), - inMemoryModule: true); + inMemoryModule: true, + isCorLib: false); } dependencies.Add(moduleData); @@ -194,9 +198,10 @@ private static List FindDirectReferencedCompilations(Compilation co List dependencies, DiagnosticBag diagnostics, CompilationTestData testData, - EmitOptions emitOptions - ) + EmitOptions emitOptions) { + var corLibIdentity = compilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly.Identity; + // A Compilation can appear multiple times in a dependency graph as both a Compilation and as a MetadataReference // value. Iterate the Compilations eagerly so they are always emitted directly and later references can re-use // the value. This gives better, and consistent, diagnostic information. @@ -208,11 +213,13 @@ EmitOptions emitOptions var emitData = EmitCompilationCore(referencedCompilation, null, diagnostics, null, emitOptions); if (emitData.HasValue) { - var moduleData = new ModuleData(referencedCompilation.Assembly.Identity, + var identity = referencedCompilation.Assembly.Identity; + var moduleData = new ModuleData(identity, OutputKind.DynamicallyLinkedLibrary, emitData.Value.Assembly, pdb: default(ImmutableArray), - inMemoryModule: true); + inMemoryModule: true, + isCorLib: corLibIdentity == identity); fullNameSet.Add(moduleData.Id.FullName); dependencies.Add(moduleData); } @@ -221,7 +228,7 @@ EmitOptions emitOptions // Now that the Compilation values have been emitted, emit the non-compilation references foreach (var current in (new[] { compilation }).Concat(referencedCompilations)) { - EmitReferences(current, fullNameSet, dependencies, diagnostics); + EmitReferences(current, fullNameSet, dependencies, diagnostics, corLibIdentity); } return EmitCompilationCore(compilation, manifestResources, diagnostics, testData, emitOptions); diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index 3d3d64f406c1e..7688a9fad3304 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -270,27 +270,9 @@ private void ILVerify(Verification verification) { var resolver = new Resolver(_allModuleData); var verifier = new ILVerify.Verifier(resolver); - var mscorlibModules = _allModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); - if (mscorlibModules.Length == 1) - { - verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].SimpleName)); - } - else - { - // ILVerify requires a "system" module to be identified (see ILVerify.Verifier.ThrowMissingSystemModule) - // So we auto-detect a candidate module - // This comes in handy in tests that use TestBase.AacorlibRef for instance. - foreach (var module in _allModuleData) - { - var name = module.SimpleName; - var metadataReader = resolver.Resolve(name).GetMetadataReader(); - if (metadataReader.AssemblyReferences.Count == 0) - { - verifier.SetSystemModuleName(new AssemblyName(name)); - break; - } - } - } + + var mscorlibModule = _allModuleData.Single(m => m.IsCorLib); + verifier.SetSystemModuleName(new AssemblyName(mscorlibModule.SimpleName)); // Main module is the first one var result = verifier.Verify(resolver.Resolve(_allModuleData[0].SimpleName)); diff --git a/src/Compilers/Test/Core/Metadata/ModuleData.cs b/src/Compilers/Test/Core/Metadata/ModuleData.cs index 712aaa4ab92e3..ddaa3ef24b9db 100644 --- a/src/Compilers/Test/Core/Metadata/ModuleData.cs +++ b/src/Compilers/Test/Core/Metadata/ModuleData.cs @@ -56,36 +56,40 @@ public sealed class ModuleData public readonly ImmutableArray Image; public readonly ImmutableArray Pdb; public readonly bool InMemoryModule; + public readonly bool IsCorLib; public string SimpleName => Id.SimpleName; public string FullName => Id.FullName; public Guid Mvid => Id.Mvid; - public ModuleData(string netModuleName, ImmutableArray image, ImmutableArray pdb, bool inMemoryModule) + public ModuleData(string netModuleName, ImmutableArray image, ImmutableArray pdb, bool inMemoryModule, bool isCorLib) { this.Id = new ModuleDataId(netModuleName, netModuleName, GetMvid(image)); this.Kind = OutputKind.NetModule; this.Image = image; this.Pdb = pdb; this.InMemoryModule = inMemoryModule; + this.IsCorLib = isCorLib; } - public ModuleData(AssemblyIdentity identity, OutputKind kind, ImmutableArray image, ImmutableArray pdb, bool inMemoryModule) + public ModuleData(AssemblyIdentity identity, OutputKind kind, ImmutableArray image, ImmutableArray pdb, bool inMemoryModule, bool isCorLib) { this.Id = new ModuleDataId(identity.Name, identity.GetDisplayName(), GetMvid(image)); this.Kind = kind; this.Image = image; this.Pdb = pdb; this.InMemoryModule = inMemoryModule; + this.IsCorLib = isCorLib; } - public ModuleData(ModuleDataId id, OutputKind kind, ImmutableArray image, ImmutableArray pdb, bool inMemoryModule) + public ModuleData(ModuleDataId id, OutputKind kind, ImmutableArray image, ImmutableArray pdb, bool inMemoryModule, bool isCorLib) { this.Id = id; this.Kind = kind; this.Image = image; this.Pdb = pdb; this.InMemoryModule = inMemoryModule; + this.IsCorLib = isCorLib; } private static Guid GetMvid(ImmutableArray image) diff --git a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 70da322483d14..67f3e3fd88cbd 100644 --- a/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -58,12 +58,15 @@ public void Emit( { var mainImage = mainOutput.Value.Assembly; var mainPdb = mainOutput.Value.Pdb; + var corLibIdentity = mainCompilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly.Identity; + var identity = mainCompilation.Assembly.Identity; _emitData.MainModule = new ModuleData( - mainCompilation.Assembly.Identity, + identity, mainCompilation.Options.OutputKind, mainImage, pdb: usePdbForDebugging ? mainPdb : default(ImmutableArray), - inMemoryModule: true); + inMemoryModule: true, + isCorLib: corLibIdentity == identity); _emitData.MainModulePdb = mainPdb; _emitData.AllModuleData = dependencies; diff --git a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs index 41df76ae1ffa3..72b58729af9da 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -214,12 +214,15 @@ public void Emit( { var mainImage = mainOutput.Value.Assembly; var mainPdb = mainOutput.Value.Pdb; + var corLibIdentity = mainCompilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly.Identity; + var identity = mainCompilation.Assembly.Identity; _emitData.MainModule = new ModuleData( - mainCompilation.Assembly.Identity, + identity, mainCompilation.Options.OutputKind, mainImage, pdb: usePdbForDebugging ? mainPdb : default(ImmutableArray), - inMemoryModule: true); + inMemoryModule: true, + isCorLib: corLibIdentity == identity); _emitData.MainModulePdb = mainPdb; _emitData.AllModuleData = dependencies; diff --git a/src/Compilers/Test/Core/Platform/Desktop/RuntimeModuleData.cs b/src/Compilers/Test/Core/Platform/Desktop/RuntimeModuleData.cs index a5d65631049e3..bf6ea756e2ed0 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/RuntimeModuleData.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/RuntimeModuleData.cs @@ -67,7 +67,8 @@ private RuntimeModuleData(SerializationInfo info, StreamingContext context) var image = info.GetByteArray(nameof(ModuleData.Image)); var pdb = info.GetByteArray(nameof(ModuleData.Pdb)); var inMemoryModule = info.GetBoolean(nameof(ModuleData.InMemoryModule)); - Data = new ModuleData(id.Id, kind, image, pdb, inMemoryModule); + var isCorLib = info.GetBoolean(nameof(ModuleData.IsCorLib)); + Data = new ModuleData(id.Id, kind, image, pdb, inMemoryModule, isCorLib); } public void GetObjectData(SerializationInfo info, StreamingContext context) @@ -77,6 +78,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context) info.AddByteArray(nameof(ModuleData.Image), Data.Image); info.AddByteArray(nameof(ModuleData.Pdb), Data.Pdb); info.AddValue(nameof(ModuleData.InMemoryModule), Data.InMemoryModule); + info.AddValue(nameof(ModuleData.IsCorLib), Data.IsCorLib); } } } diff --git a/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb b/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb index 7562e21cb0a4e..2e1a86fa17737 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Attributes/AssemblyAttributes.vb @@ -566,7 +566,7 @@ end class dependencies:={New ModuleData(en_usRef.Compilation.Assembly.Identity, OutputKind.DynamicallyLinkedLibrary, en_usRef.Compilation.EmitToArray(), - ImmutableArray(Of Byte).Empty, False)}). + ImmutableArray(Of Byte).Empty, False, False)}). VerifyDiagnostics() compilation = CreateCompilationWithMscorlib40AndReferences( @@ -599,11 +599,11 @@ end class dependencies:={New ModuleData(en_UKRef.Compilation.Assembly.Identity, OutputKind.DynamicallyLinkedLibrary, en_UKRef.Compilation.EmitToArray(), - ImmutableArray(Of Byte).Empty, False), + ImmutableArray(Of Byte).Empty, False, False), New ModuleData(neutralRef.Compilation.Assembly.Identity, OutputKind.DynamicallyLinkedLibrary, neutralRef.Compilation.EmitToArray(), - ImmutableArray(Of Byte).Empty, False)}, + ImmutableArray(Of Byte).Empty, False, False)}, sourceSymbolValidator:=Sub(m As ModuleSymbol) Assert.Equal(1, m.GetReferencedAssemblySymbols().Length) diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb index fd4065bf7f78e..cf6dd5aad69b6 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb @@ -665,7 +665,8 @@ BC30652: Reference required to assembly 'mincorlib, Version=0.0.0.0, Culture=neu Dim compilation5 = CreateEmptyCompilationWithReferences(source2, options:=TestOptions.ReleaseDll, references:={compilation1.ToMetadataReference()}) compilation5.VerifyEmitDiagnostics() - CompileAndVerify(compilation5) + ' ILVerify: no corlib + CompileAndVerify(compilation5, verify:=Verification.FailsIlVerify) Assert.Equal(TypeKind.Struct, compilation5.GetTypeByMetadataName("A").TypeKind) Assert.Equal(TypeKind.Enum, compilation5.GetTypeByMetadataName("B").TypeKind) diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/NoPia.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/NoPia.vb index c8027ff848044..0d5e9629e8a30 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/NoPia.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/NoPia.vb @@ -1241,6 +1241,7 @@ End Class OutputKind.DynamicallyLinkedLibrary, i3Compilation.EmitToArray(), Nothing, + False, False)}, expectedOutput:= Date: Mon, 31 Jan 2022 12:02:05 -0800 Subject: [PATCH 39/51] Use label for version number --- eng/Versions.props | 1 + .../Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 08e072387d3df..ef18c3309abb6 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -37,6 +37,7 @@ but not higher than our minimum dogfoodable Visual Studio version, or else the generators we build would load on the command line but not load in IDEs. --> 3.8.0 + 7.0.0-alpha.1.22060.1