From 7273f13db6f26f24764fdf13c690b5a2e7215940 Mon Sep 17 00:00:00 2001 From: Eugene Rozenfeld Date: Tue, 24 Apr 2018 22:36:19 -0700 Subject: [PATCH] Fix TailCallStress mode to do more legality checks (#17763) Check with EE whether tail call is allowed before adding tail. prefix in TailCallStress mode. --- src/jit/importer.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index 6383ba5..905cb97 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -13395,16 +13395,24 @@ void Compiler::impImportBlockCode(BasicBlock* block) // make it jump to RET. (OPCODE)getU1LittleEndian(codeAddr + sz) == CEE_RET; // Next opcode is a CEE_RET - if (newBBcreatedForTailcallStress && - !(prefixFlags & PREFIX_TAILCALL_EXPLICIT) && // User hasn't set "tail." prefix yet. + bool hasTailPrefix = (prefixFlags & PREFIX_TAILCALL_EXPLICIT); + if (newBBcreatedForTailcallStress && !hasTailPrefix && // User hasn't set "tail." prefix yet. verCheckTailCallConstraint(opcode, &resolvedToken, constraintCall ? &constrainedResolvedToken : nullptr, true) // Is it legal to do tailcall? ) { - // Stress the tailcall. - JITDUMP(" (Tailcall stress: prefixFlags |= PREFIX_TAILCALL_EXPLICIT)"); - prefixFlags |= PREFIX_TAILCALL_EXPLICIT; + CORINFO_METHOD_HANDLE declaredCalleeHnd = callInfo.hMethod; + bool isVirtual = (callInfo.kind == CORINFO_VIRTUALCALL_STUB) || + (callInfo.kind == CORINFO_VIRTUALCALL_VTABLE); + CORINFO_METHOD_HANDLE exactCalleeHnd = isVirtual ? nullptr : declaredCalleeHnd; + if (info.compCompHnd->canTailCall(info.compMethodHnd, declaredCalleeHnd, exactCalleeHnd, + hasTailPrefix)) // Is it legal to do tailcall? + { + // Stress the tailcall. + JITDUMP(" (Tailcall stress: prefixFlags |= PREFIX_TAILCALL_EXPLICIT)"); + prefixFlags |= PREFIX_TAILCALL_EXPLICIT; + } } } } -- 2.7.4