From 234766bed904a781ba94b09a4be1165d00aeb3ae Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Thu, 30 Nov 2023 03:18:06 -0500 Subject: [PATCH] [mono][jit] Fix the bblock check in the box+callvirt optimization. Fixes https://github.com/dotnet/runtime/issues/95347. --- src/mono/mono/mini/method-to-ir.c | 5 ++--- .../JitBlue/Runtime_95347/Runtime_95347.cs | 16 ++++++++++++++++ .../JitBlue/Runtime_95347/Runtime_95347.csproj | 8 ++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.csproj diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index dedc6804c3cbd..eb0ab5f4e296c 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -9707,12 +9707,11 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b // callvirt instance ISomeIface::Method() // TO // call SomeStruct::Method() - guchar* callvirt_ip; guint32 callvirt_proc_token; if (!((cfg->compile_aot || cfg->compile_llvm) && !mono_class_is_def(klass)) && // we cannot devirtualize in AOT when using generics next_ip < end && - (callvirt_ip = il_read_callvirt (next_ip, end, &callvirt_proc_token)) && - ip_in_bb (cfg, cfg->cbb, callvirt_ip) ) { + il_read_callvirt (next_ip, end, &callvirt_proc_token) && + ip_in_bb (cfg, cfg->cbb, next_ip) ) { MonoMethod* iface_method; MonoMethodSignature* iface_method_sig; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.cs b/src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.cs new file mode 100644 index 0000000000000..594d61a477362 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.cs @@ -0,0 +1,16 @@ +// 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 Xunit; + +public static class Runtime_95347 +{ + [Fact] + public static int Test() + { + object? n = "abcd"; + var s = (n ?? false).ToString(); + return (s == "abcd") ? 100 : -1; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.csproj new file mode 100644 index 0000000000000..15edd99711a1a --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_95347/Runtime_95347.csproj @@ -0,0 +1,8 @@ + + + True + + + + + \ No newline at end of file