From ef5c0c846a1a25a4662a6e2aef3565357c886399 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Fri, 27 Jan 2017 15:29:33 -0800 Subject: [PATCH] add end to end stack depth test (#16729) * add end to end stack depth test * add comment explaining test * switch to verify diagnostics * turn parallel build off * check pointer size in addition to debug/release --- .../Test/Emit/CSharpCompilerEmitTest.csproj | 1 + .../CSharp/Test/Emit/Emit/EndToEndTests.cs | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs diff --git a/src/Compilers/CSharp/Test/Emit/CSharpCompilerEmitTest.csproj b/src/Compilers/CSharp/Test/Emit/CSharpCompilerEmitTest.csproj index a33d4ab2f03..bde34582af0 100644 --- a/src/Compilers/CSharp/Test/Emit/CSharpCompilerEmitTest.csproj +++ b/src/Compilers/CSharp/Test/Emit/CSharpCompilerEmitTest.csproj @@ -145,6 +145,7 @@ + diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs new file mode 100644 index 00000000000..f4757fd1e81 --- /dev/null +++ b/src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs @@ -0,0 +1,78 @@ +using Roslyn.Test.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; +using Microsoft.CodeAnalysis.Test.Utilities; +namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Emit +{ + public class EndToEndTests: EmitMetadataTestBase + { + // This test is a canary attempting to make sure that we don't regress the # of fluent calls that + // the compiler can handle. + [WorkItem(16669, "https://github.com/dotnet/roslyn/issues/16669")] + [Fact] + public void OverflowOnFluentCall() + { + + int numberFluentCalls = 0; + +#if DEBUG + bool isDebug = true; +#else + bool isDebug = false; +#endif + + switch (IntPtr.Size * 8) { + case 32 when isDebug: + numberFluentCalls = 290; + break; + case 32 when !isDebug: + numberFluentCalls = 590; + break; + case 64 when isDebug: + numberFluentCalls = 110; + break; + case 64 when !isDebug: + numberFluentCalls = 310; + break; + default: + throw new Exception($"unexpected pointer size {IntPtr.Size}"); + } + + + string MakeCode() + { + var builder = new StringBuilder(); + builder.AppendLine( + @"class C { + C M(string x) { return this; } + void M2() { + new C() +"); + for (int i = 0; i < numberFluentCalls; i++) + { + builder.AppendLine(@" .M(""test"")"); + } + builder.AppendLine( + @" .M(""test""); + } +}"); + return builder.ToString(); + } + var source = MakeCode(); + + var thread = new System.Threading.Thread(() => + { + var options = new CSharpCompilationOptions(outputKind: OutputKind.DynamicallyLinkedLibrary, concurrentBuild: false); + var compilation = CreateCompilationWithMscorlib(source, options: options); + compilation.VerifyDiagnostics(); + compilation.EmitToArray(); + }, 0); + thread.Start(); + thread.Join(); + } + } +} -- GitLab