[release/6.0] [mono][jit] Fix an infinite loop in the abcrem pass. (#72504)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Thu, 11 Aug 2022 20:00:55 +0000 (13:00 -0700)
committerGitHub <noreply@github.com>
Thu, 11 Aug 2022 20:00:55 +0000 (13:00 -0700)
* [mono][jit] Fix an infinite loop in the abcrem pass.

Fixes https://github.com/dotnet/runtime/issues/71592.

* Add a test.

* Fix pri1 test build

* Fix the test.

* Update src/tests/JIT/Regression/JitBlue/Runtime_71592/test71592.csproj

Co-authored-by: Aleksey Kliger (λgeek) <aleksey@lambdageek.org>
Co-authored-by: Zoltan Varga <vargaz@gmail.com>
Co-authored-by: Jakob Botsch Nielsen <jakob.botsch.nielsen@gmail.com>
Co-authored-by: Aleksey Kliger (λgeek) <aleksey@lambdageek.org>
src/mono/mono/mini/abcremoval.c
src/tests/JIT/Regression/JitBlue/Runtime_71592/test71592.cs [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_71592/test71592.csproj [new file with mode: 0644]

index 44317cd..c758a48 100644 (file)
@@ -493,7 +493,7 @@ get_relations_from_previous_bb (MonoVariableRelationsEvaluationArea *area, MonoB
                        symmetric_relation = MONO_SYMMETRIC_RELATION (branch_relation);
 
                        /* FIXME: Other compare opcodes */
-                       if (compare->opcode == OP_ICOMPARE) {
+                       if (compare->opcode == OP_ICOMPARE && compare->sreg1 != compare->sreg2) {
                                relations->relation1.variable = compare->sreg1;
                                relations->relation1.relation.relation = branch_relation;
                                relations->relation1.relation.related_value.type = MONO_VARIABLE_SUMMARIZED_VALUE;
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71592/test71592.cs b/src/tests/JIT/Regression/JitBlue/Runtime_71592/test71592.cs
new file mode 100644 (file)
index 0000000..21912e0
--- /dev/null
@@ -0,0 +1,33 @@
+// 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.Threading.Tasks;
+
+public class Test
+{
+    public int foo;
+
+    public override bool Equals(object o) => false;
+    public override int GetHashCode() => 0;
+
+    public static bool operator ==(Test t1, Test t2) {
+        if (ReferenceEquals(t1, t1))
+            return true;
+        return t1.foo == t2.foo;
+    }
+
+    public static bool operator !=(Test t1, Test t2) {
+        if (ReferenceEquals(t1, t1))
+            return true;
+        return t1.foo == t2.foo;
+    }
+
+    public static int Main () {
+        var t1 = new Test () { foo = 1 };
+        var t2 = new Test () { foo = 2 };
+        if (t1 == t2)
+            return 100;
+        return 100;
+    }
+}
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71592/test71592.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_71592/test71592.csproj
new file mode 100644 (file)
index 0000000..4ccbe30
--- /dev/null
@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <CLRTestPriority>0</CLRTestPriority>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="test71592.cs" />
+  </ItemGroup>
+</Project>