Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Wasm: do not sign extend bools #8322

Merged
merged 1 commit into from
Sep 13, 2020
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
2 changes: 1 addition & 1 deletion src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilde
LLVMTypeRef origLLVMType = ILImporter.GetLLVMTypeForTypeDesc(Type);
LLVMValueRef value = _importer.LoadTemp(LocalIndex, origLLVMType);

return ILImporter.CastIfNecessary(builder, value, type);
return ILImporter.CastIfNecessary(builder, value, type, unsigned: !signExtend);
}

public override StackEntry Duplicate(LLVMBuilderRef builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,7 @@ bool TypeNeedsSignExtension(TypeDesc targetType)
if (enumCleanTargetType != null && targetType.IsPrimitive)
{
if (enumCleanTargetType.IsWellKnownType(WellKnownType.Byte) ||
enumCleanTargetType.IsWellKnownType(WellKnownType.Boolean) ||
enumCleanTargetType.IsWellKnownType(WellKnownType.Char) ||
enumCleanTargetType.IsWellKnownType(WellKnownType.UInt16) ||
enumCleanTargetType.IsWellKnownType(WellKnownType.UInt32) ||
Expand Down Expand Up @@ -4145,7 +4146,7 @@ private void ImportCompareOperation(ILOpcode opcode)
}
}

PushExpression(StackValueKind.Int32, "cmpop", result, GetWellKnownType(WellKnownType.SByte));
PushExpression(StackValueKind.Int32, "cmpop", result, GetWellKnownType(WellKnownType.UInt32));
}

private void ImportConvert(WellKnownType wellKnownType, bool checkOverflow, bool unsigned)
Expand Down
10 changes: 10 additions & 0 deletions tests/src/Simple/HelloWasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ private static unsafe int Main(string[] args)

TestGetSystemArrayEEType();

TestBoolCompare();

// This test should remain last to get other results before stopping the debugger
PrintLine("Debugger.Break() test: Ok if debugger is open and breaks.");
System.Diagnostics.Debugger.Break();
Expand Down Expand Up @@ -2922,6 +2924,14 @@ static void TestGetSystemArrayEEType()
EndTest(true); // testing compilation
}

static void TestBoolCompare()
{
StartTest("Test Bool.Equals");
bool expected = true;
bool actual = true;
EndTest(expected.Equals(actual));
}

static ushort ReadUInt16()
{
// something with MSB set
Expand Down