Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer to string conversion when generating code #7941

Merged
merged 4 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,22 @@ public static string [] SupportedTargetFrameworks ()
}

[Test]
public void BuildBasicApplication ([ValueSource (nameof (SupportedTargetFrameworks))] string tfv, [Values (true, false)] bool isRelease)
public void BuildBasicApplication ([ValueSource (nameof (SupportedTargetFrameworks))] string tfv, [Values (true, false)] bool isRelease, [Values ("", "en_US.UTF-8", "sv_SE.UTF-8")] string langEnvironmentVariable)
{
var proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
TargetFrameworkVersion = tfv,
};

Dictionary<string, string> envvar = null;
if (!String.IsNullOrEmpty (langEnvironmentVariable)) {
envvar = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase) {
{"LANG", langEnvironmentVariable},
};
}

using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Assert.IsTrue (b.Build (proj, environmentVariables: envvar), "Build should have succeeded.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

using Java.Interop.Tools.TypeNameMappings;
Expand Down Expand Up @@ -253,7 +254,7 @@ List<StructureInstance<DSOCacheEntry>> InitDSOCache ()
continue;
}

dsos.Add ((name, $"dsoName{dsos.Count}", ELFHelper.IsEmptyAOTLibrary (log, item.ItemSpec)));
dsos.Add ((name, $"dsoName{dsos.Count.ToString (CultureInfo.InvariantCulture)}", ELFHelper.IsEmptyAOTLibrary (log, item.ItemSpec)));
}

var dsoCache = new List<StructureInstance<DSOCacheEntry>> ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text;
using System.Globalization;

namespace Xamarin.Android.Tasks.LLVMIR
{
Expand Down Expand Up @@ -113,7 +114,7 @@ public AlignstackFunctionAttribute (uint powerOfTwoAlignment)

protected override void RenderParams (StringBuilder sb)
{
sb.Append (alignment);
sb.Append (alignment.ToString (CultureInfo.InvariantCulture));
}
}

Expand Down Expand Up @@ -165,13 +166,13 @@ public AllocsizeFunctionAttribute (uint elementSize, uint? numberOfElements = nu

protected override void RenderParams (StringBuilder sb)
{
sb.Append (elementSize);
sb.Append (elementSize.ToString (CultureInfo.InvariantCulture));
if (!numberOfElements.HasValue) {
return;
}

sb.Append (", ");
sb.Append (numberOfElements.Value);
sb.Append (numberOfElements.Value.ToString (CultureInfo.InvariantCulture));
}
}

Expand Down Expand Up @@ -701,13 +702,13 @@ public VscaleRangeFunctionAttribute (uint min, uint? max = null)

protected override void RenderParams (StringBuilder sb)
{
sb.Append (min);
sb.Append (min.ToString (CultureInfo.InvariantCulture));
if (!max.HasValue) {
return;
}

sb.Append (", ");
sb.Append (max.Value);
sb.Append (max.Value.ToString (CultureInfo.InvariantCulture));
}
}

Expand All @@ -721,7 +722,7 @@ public MinLegalVectorWidthFunctionAttribute (uint size)
this.size = size;
}

protected override void RenderAssignedValue (StringBuilder sb) => sb.Append (size);
protected override void RenderAssignedValue (StringBuilder sb) => sb.Append (size.ToString (CultureInfo.InvariantCulture));
}

class StackProtectorBufferSizeFunctionAttribute : LLVMFunctionAttribute
Expand All @@ -734,7 +735,7 @@ public StackProtectorBufferSizeFunctionAttribute (uint size)
this.size = size;
}

protected override void RenderAssignedValue (StringBuilder sb) => sb.Append (size);
protected override void RenderAssignedValue (StringBuilder sb) => sb.Append (size.ToString (CultureInfo.InvariantCulture));
}

class TargetCpuFunctionAttribute : LLVMFunctionAttribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Globalization;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Xamarin.Android.Tasks.LLVMIR
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;

Expand Down Expand Up @@ -52,7 +53,7 @@ public void WriteFunctionStart (LlvmIrFunction function, string? comment = null)
WriteFunctionParameters (function.Parameters, writeNames: true);
Output.Write(") local_unnamed_addr ");
if (attributes != null) {
Output.Write ($"#{function.AttributeSetID}");
Output.Write ($"#{function.AttributeSetID.ToString (CultureInfo.InvariantCulture)}");
}
Output.WriteLine ();
Output.WriteLine ("{");
Expand Down Expand Up @@ -184,7 +185,7 @@ public void EmitStoreInstruction (LlvmIrFunction function, LlvmIrFunctionLocalVa
CodeRenderType (source);
Output.Write ($" %{source.Name}, ");
CodeRenderType (destination);
Output.WriteLine ($"* {destination.Reference}, align {GetTypeSize (destination.Type)}");
Output.WriteLine ($"* {destination.Reference}, align {GetTypeSize (destination.Type).ToString (CultureInfo.InvariantCulture)}");
}

/// <summary>
Expand All @@ -201,7 +202,7 @@ public LlvmIrFunctionLocalVariable EmitLoadInstruction (LlvmIrFunction function,

string variableType = sb.ToString ();
LlvmIrFunctionLocalVariable result = function.MakeLocalVariable (source, resultVariableName);
Output.WriteLine ($"{function.Indent}%{result.Name} = load {variableType}, {variableType}* @{source.Name}, align {PointerSize}");
Output.WriteLine ($"{function.Indent}%{result.Name} = load {variableType}, {variableType}* @{source.Name}, align {PointerSize.ToString (CultureInfo.InvariantCulture)}");

return result;
}
Expand Down Expand Up @@ -378,7 +379,8 @@ public void EmitLabel (LlvmIrFunction function, string labelName)
Output.Write ("nonnull ");
}

Output.Write ($"align {PointerSize} dereferenceable({PointerSize}) ");
string ptrSize = PointerSize.ToString (CultureInfo.InvariantCulture);
Output.Write ($"align {ptrSize} dereferenceable({ptrSize}) ");

if (argument.Value is LlvmIrVariableReference variableRef) {
bool needBitcast = parameter.Type != argument.Type;
Expand Down Expand Up @@ -409,7 +411,7 @@ public void EmitLabel (LlvmIrFunction function, string labelName)
if (!FunctionAttributes.ContainsKey (AttributeSetID)) {
throw new InvalidOperationException ($"Unknown attribute set ID {AttributeSetID}");
}
Output.Write ($" #{AttributeSetID}");
Output.Write ($" #{AttributeSetID.ToString (CultureInfo.InvariantCulture)}");
}
Output.WriteLine ();

Expand Down Expand Up @@ -538,7 +540,7 @@ void WriteAttributeSets ()

void WriteSet (int id, TextWriter output)
{
output.Write ($"attributes #{id} = {{ ");
output.Write ($"attributes #{id.ToString (CultureInfo.InvariantCulture)} = {{ ");
foreach (LLVMFunctionAttribute attr in FunctionAttributes[id]) {
output.Write (attr.Render ());
output.Write (' ');
Expand Down
Loading