From: Akihiko Odaki Date: Thu, 14 Mar 2019 12:39:29 +0000 (+0900) Subject: [XamlC] Correctly load addresses of values in compiled binding paths (#5082) X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~466^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12f5b702ef4c8bcbd343b6272555ba9f01b36438;p=platform%2Fcore%2Fcsapi%2Fxsf.git [XamlC] Correctly load addresses of values in compiled binding paths (#5082) --- diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs index 5d6194a..0d455f6 100644 --- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs +++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs @@ -527,6 +527,8 @@ namespace Xamarin.Forms.Build.Tasks il.Emit(Ret); } else { + var locs = new Dictionary(); + if (tSourceRef.IsValueType) il.Emit(Ldarga_S, (byte)0); else @@ -535,6 +537,19 @@ namespace Xamarin.Forms.Build.Tasks for (int i = 0; i < properties.Count; i++) { (PropertyDefinition property, TypeReference propDeclTypeRef, string indexArg) = properties[i]; + if (i > 0 && propDeclTypeRef.IsValueType) { + var importedPropDeclTypeRef = module.ImportReference(propDeclTypeRef); + + if (!locs.TryGetValue(importedPropDeclTypeRef, out var loc)) { + loc = new VariableDefinition(importedPropDeclTypeRef); + getter.Body.Variables.Add(loc); + locs[importedPropDeclTypeRef] = loc; + } + + il.Emit(Stloc, loc); + il.Emit(Ldloca, loc); + } + if (!property.PropertyType.IsValueType) { //if part of the path is null, return (default(T), false) var nop = Create(Nop); il.Emit(Dup); @@ -543,8 +558,14 @@ namespace Xamarin.Forms.Build.Tasks il.Emit(Brfalse, nop); il.Emit(Pop); if (tPropertyRef.IsValueType) { - var defaultValueVarDef = new VariableDefinition(tPropertyRef); - getter.Body.Variables.Add(defaultValueVarDef); + var importedTPropertyRef = module.ImportReference(tPropertyRef); + + if (!locs.TryGetValue(importedTPropertyRef, out var defaultValueVarDef)) { + defaultValueVarDef = new VariableDefinition(tPropertyRef); + getter.Body.Variables.Add(defaultValueVarDef); + locs[importedTPropertyRef] = defaultValueVarDef; + } + il.Emit(Ldloca_S, defaultValueVarDef); il.Emit(Initobj, tPropertyRef); il.Emit(Ldloc, defaultValueVarDef); diff --git a/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml b/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml index 59a15f3..fda4a67 100644 --- a/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml @@ -18,6 +18,7 @@