diff --git a/src/System.Linq.Expressions/tests/CompilerTests.cs b/src/System.Linq.Expressions/tests/CompilerTests.cs index 1b55caa765d8..822414f9b817 100644 --- a/src/System.Linq.Expressions/tests/CompilerTests.cs +++ b/src/System.Linq.Expressions/tests/CompilerTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Threading; using Xunit; namespace System.Linq.Expressions.Tests @@ -26,6 +27,28 @@ public static void CompileDeepTree_NoStackOverflow(bool useInterpreter) Assert.Equal(n, f()); } + [Theory, ClassData(typeof(CompilationTypes))] + public static void CompileDeepTree_NoStackOverflowFast(bool useInterpreter) + { + Expression e = Expression.Constant(0); + + int n = 100; + + for (int i = 0; i < n; i++) + e = Expression.Add(e, Expression.Constant(1)); + + Func f = null; + // Request a stack size of 1 to get the minimum size allowed. + // This reduces the size of tree needed to risk a stack overflow. + // This though will only risk overflow once, so the outerloop test + // above is still needed. + Thread t = new Thread(() => f = Expression.Lambda>(e).Compile(useInterpreter), 1); + t.Start(); + t.Join(); + + Assert.Equal(n, f()); + } + #if FEATURE_COMPILE [Fact] public static void EmitConstantsToIL_NonNullableValueTypes()