diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs b/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs index 0e55fe23029..685622d2fcb 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs @@ -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) diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs index c08f9658a98..76d29e7de35 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs @@ -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) || @@ -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) diff --git a/tests/src/Simple/HelloWasm/Program.cs b/tests/src/Simple/HelloWasm/Program.cs index eddf007da00..523a8e15e8b 100644 --- a/tests/src/Simple/HelloWasm/Program.cs +++ b/tests/src/Simple/HelloWasm/Program.cs @@ -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(); @@ -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