From 8cd464a6adfb7c28b4e05cfc7a921e71b551ed38 Mon Sep 17 00:00:00 2001 From: vsadov Date: Thu, 19 Oct 2017 15:18:26 -0700 Subject: [PATCH] Enable peverify compat mode in langver < 7.2 --- .../CSharp/Portable/CodeGen/CodeGenerator.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CodeGen/CodeGenerator.cs b/src/Compilers/CSharp/Portable/CodeGen/CodeGenerator.cs index 24a1bb6495f95..281c9821afef6 100644 --- a/src/Compilers/CSharp/Portable/CodeGen/CodeGenerator.cs +++ b/src/Compilers/CSharp/Portable/CodeGen/CodeGenerator.cs @@ -139,7 +139,7 @@ private bool IsDebugPlus() private bool EnablePEVerifyCompat() { - return _module.Compilation.FeaturePEVerifyCompatEnabled; + return _module.Compilation.LanguageVersion < LanguageVersion.CSharp7_2 || _module.Compilation.FeaturePEVerifyCompatEnabled; } private LocalDefinition LazyReturnTemp diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index 2ade9d50ba8d5..9d9fa9b872913 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -12025,7 +12025,7 @@ public MyManagedStruct(int x) n.n.num = x; } }"; - var comp = CompileAndVerify(source, expectedOutput: @"42", verify: false); + var comp = CompileAndVerify(source, expectedOutput: @"42", parseOptions: TestOptions.Regular7_2, verify: false); comp.VerifyIL("Program.Main", @" @@ -12088,6 +12088,38 @@ .locals init (MyManagedStruct V_0) IL_0046: call ""void System.Console.WriteLine(int)"" IL_004b: ret } +"); + + comp = CompileAndVerify(source, expectedOutput: @"42", verify: true, parseOptions: TestOptions.Regular7_1); + + comp.VerifyIL("Program.Main", +@" +{ + // Code size 76 (0x4c) + .maxstack 3 + .locals init (MyManagedStruct V_0) + IL_0000: newobj ""cls1..ctor()"" + IL_0005: dup + IL_0006: ldfld ""MyManagedStruct cls1.y"" + IL_000b: stloc.0 + IL_000c: ldloca.s V_0 + IL_000e: ldc.i4.s 123 + IL_0010: call ""void MyManagedStruct.mutate(int)"" + IL_0015: dup + IL_0016: ldfld ""MyManagedStruct cls1.y"" + IL_001b: stloc.0 + IL_001c: ldloca.s V_0 + IL_001e: ldflda ""MyManagedStruct.Nested MyManagedStruct.n"" + IL_0023: ldflda ""MyManagedStruct.Nested.Nested1 MyManagedStruct.Nested.n"" + IL_0028: ldc.i4 0x1c8 + IL_002d: call ""void MyManagedStruct.Nested.Nested1.mutate(int)"" + IL_0032: ldfld ""MyManagedStruct cls1.y"" + IL_0037: ldfld ""MyManagedStruct.Nested MyManagedStruct.n"" + IL_003c: ldfld ""MyManagedStruct.Nested.Nested1 MyManagedStruct.Nested.n"" + IL_0041: ldfld ""int MyManagedStruct.Nested.Nested1.num"" + IL_0046: call ""void System.Console.WriteLine(int)"" + IL_004b: ret +} "); }