From: Marek Safar Date: Fri, 26 May 2017 16:22:58 +0000 (+0200) Subject: [mcs] Codegen for optimized new with valuetype load and awaited arguments. Fixes... X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=84bac28050ae38c73451b72a8cad2edfc3943f02 [mcs] Codegen for optimized new with valuetype load and awaited arguments. Fixes #56081 --- diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index c054330db20..9042dcdabad 100644 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -7570,14 +7570,21 @@ namespace Mono.CSharp bool is_value_type = type.IsStructOrEnum; VariableReference vr = target as VariableReference; + bool prepare_await = ec.HasSet (BuilderContext.Options.AsyncBody) && arguments?.ContainsEmitWithAwait () == true; + if (target != null && is_value_type && (vr != null || method == null)) { + if (prepare_await) { + arguments = arguments.Emit (ec, false, true); + prepare_await = false; + } + target.AddressOf (ec, AddressOp.Store); } else if (vr != null && vr.IsRef) { vr.EmitLoad (ec); } if (arguments != null) { - if (ec.HasSet (BuilderContext.Options.AsyncBody) && (arguments.Count > (this is NewInitialize ? 0 : 1)) && arguments.ContainsEmitWithAwait ()) + if (prepare_await) arguments = arguments.Emit (ec, false, true); arguments.Emit (ec); diff --git a/mcs/tests/test-async-92.cs b/mcs/tests/test-async-92.cs new file mode 100644 index 00000000000..e41ac00a531 --- /dev/null +++ b/mcs/tests/test-async-92.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; + +public class A +{ + public async Task Test1 (int input2) + { + return new ValueType (await Task.FromResult (12345)); + } + + public static void Main () + { + var a = new A (); + a.Test1 (1).Wait (); + } +} + +public struct ValueType +{ + public ValueType (int field2) + { + } +} diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 4882b788602..b06aba48fd5 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -52705,6 +52705,24 @@ + + + + 14 + + + 8 + + + + + 44 + + + 7 + + + @@ -66729,6 +66747,32 @@ + + + + 33 + + + 20 + + + 7 + + + + + 2 + + + + + 174 + + + 13 + + +