JIT: tolerate byref/nint return type mismatches during inlining (#18274)
authorAndy Ayers <andya@microsoft.com>
Mon, 4 Jun 2018 23:02:01 +0000 (16:02 -0700)
committerGitHub <noreply@github.com>
Mon, 4 Jun 2018 23:02:01 +0000 (16:02 -0700)
Have the jit tolerate byref/nint return type mismatches for inlines
same way that it tolerates them for ret instructions.

Fixes #18270.

src/jit/importer.cpp

index 0811e7b..d7f0fe8 100644 (file)
@@ -15777,10 +15777,20 @@ bool Compiler::impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE&
 
             if (returnType != originalCallType)
             {
-                JITDUMP("Return type mismatch, have %s, needed %s\n", varTypeName(returnType),
-                        varTypeName(originalCallType));
-                compInlineResult->NoteFatal(InlineObservation::CALLSITE_RETURN_TYPE_MISMATCH);
-                return false;
+                // Allow TYP_BYREF to be returned as TYP_I_IMPL and vice versa
+                if (((returnType == TYP_BYREF) && (originalCallType == TYP_I_IMPL)) ||
+                    ((returnType == TYP_I_IMPL) && (originalCallType == TYP_BYREF)))
+                {
+                    JITDUMP("Allowing return type mismatch: have %s, needed %s\n", varTypeName(returnType),
+                            varTypeName(originalCallType));
+                }
+                else
+                {
+                    JITDUMP("Return type mismatch: have %s, needed %s\n", varTypeName(returnType),
+                            varTypeName(originalCallType));
+                    compInlineResult->NoteFatal(InlineObservation::CALLSITE_RETURN_TYPE_MISMATCH);
+                    return false;
+                }
             }
 
             // Below, we are going to set impInlineInfo->retExpr to the tree with the return