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

Commit

Permalink
wasm: do not sign extend bools (#8322)
Browse files Browse the repository at this point in the history
  • Loading branch information
yowl authored Sep 13, 2020
1 parent 3a61912 commit 9fd5738
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit 9fd5738

Please sign in to comment.