diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 99991e9c5d51a6..68927c1acf465b 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -4699,6 +4699,13 @@ GenTree* Compiler::optAssertionPropLocal_RelOp(ASSERT_VALARG_TP assertions, GenT // Find an equal or not equal assertion about op1 var. unsigned lclNum = op1->AsLclVarCommon()->GetLclNum(); + + // Make sure the local is not truncated. + if (!op1->TypeIs(lvaGetRealType(lclNum))) + { + return nullptr; + } + noway_assert(lclNum < lvaCount); AssertionIndex index = optLocalAssertionIsEqualOrNotEqual(op1Kind, lclNum, op2Kind, cnsVal, assertions); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_119654/Runtime_119654.cs b/src/tests/JIT/Regression/JitBlue/Runtime_119654/Runtime_119654.cs new file mode 100644 index 00000000000000..46e5cb0b16ade1 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_119654/Runtime_119654.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.CompilerServices; +using Xunit; + +public class Runtime_119654 +{ + [Fact] + public static void TestEntryPoint() + { + if (ShouldReturnOne(-4294967296L) != 1) + { + throw new Exception("Test failed"); + } + } + + [MethodImpl(MethodImplOptions.NoInlining | + MethodImplOptions.AggressiveOptimization)] + private static int ShouldReturnOne(long availableSigned) + { + if (availableSigned == 0L) + return 0; + return (uint)(ulong)availableSigned != 0 ? 111 : 1; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_119654/Runtime_119654.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_119654/Runtime_119654.csproj new file mode 100644 index 00000000000000..501217e4d86892 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_119654/Runtime_119654.csproj @@ -0,0 +1,9 @@ + + + None + True + + + + +