Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ed04998

Browse files
committed
Some tests for caller/callee type mismatches
Ensure the jit can avoid or back out of inlines where types are mismatched. Remove some assertion checking that was looking at call actuals versus formals and instead let the newly added inline bail out handle cases where there are mismatches.
1 parent 6eb5e5d commit ed04998

File tree

7 files changed

+254
-60
lines changed

7 files changed

+254
-60
lines changed

src/jit/importer.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -950,66 +950,6 @@ GenTreeArgList* Compiler::impPopList(unsigned count,
950950
info.compCompHnd->classMustBeLoadedBeforeCodeIsRun(argRealClass);
951951
}
952952

953-
#ifdef DEBUG
954-
// Ensure that IL is half-way sane (what was pushed is what the function expected)
955-
var_types argType = genActualType(args->Current()->TypeGet());
956-
unsigned argSize = genTypeSize(argType);
957-
if (varTypeIsStruct(argType))
958-
{
959-
if (args->Current()->gtOper == GT_LDOBJ)
960-
argSize = info.compCompHnd->getClassSize(args->Current()->gtLdObj.gtClass);
961-
else if (args->Current()->gtOper == GT_MKREFANY)
962-
argSize = 2 * sizeof(void*);
963-
else if (args->Current()->gtOper == GT_RET_EXPR)
964-
{
965-
CORINFO_SIG_INFO *callArgs = &args->Current()->gtRetExpr.gtInlineCandidate->gtCall.gtInlineCandidateInfo->methInfo.args;
966-
assert(callArgs->retType == CORINFO_TYPE_VALUECLASS);
967-
argSize = info.compCompHnd->getClassSize(callArgs->retTypeClass);
968-
}
969-
else if (args->Current()->gtOper == GT_LCL_VAR)
970-
{
971-
argSize = lvaLclSize(args->Current()->gtLclVarCommon.gtLclNum);
972-
}
973-
else if (args->Current()->gtOper == GT_CALL)
974-
{
975-
if (args->Current()->gtCall.gtInlineCandidateInfo)
976-
{
977-
CORINFO_SIG_INFO *callArgs = &args->Current()->gtCall.gtInlineCandidateInfo->methInfo.args;
978-
assert(callArgs->retType == CORINFO_TYPE_VALUECLASS);
979-
argSize = info.compCompHnd->getClassSize(callArgs->retTypeClass);
980-
}
981-
else if (!(args->Current()->gtCall.gtCallMoreFlags & GTF_CALL_M_RETBUFFARG))
982-
{
983-
assert((var_types)args->Current()->gtCall.gtReturnType != TYP_STRUCT);
984-
argSize = genTypeSize((var_types)args->Current()->gtCall.gtReturnType);
985-
}
986-
else
987-
{
988-
// No easy way to recover the return type size, so just give up
989-
goto SKIP_SIZE_CHECK;
990-
}
991-
}
992-
else
993-
{
994-
assert(!"Unexpeced tree node with type TYP_STRUCT");
995-
goto SKIP_SIZE_CHECK;
996-
}
997-
}
998-
999-
sigSize = compGetTypeSize(corType, argClass);
1000-
if (argSize != sigSize)
1001-
{
1002-
var_types sigType = genActualType(JITtype2varType(corType));
1003-
char buff[400];
1004-
sprintf_s(buff, sizeof(buff), "Arg type mismatch: Wanted %s (size %d), Got %s (size %d) for call at IL offset 0x%x\n",
1005-
varTypeName(sigType), sigSize, varTypeName(argType), argSize, impCurOpcOffs);
1006-
assertAbort(buff, __FILE__, __LINE__);
1007-
}
1008-
1009-
SKIP_SIZE_CHECK:
1010-
1011-
#endif // DEBUG
1012-
1013953
argLst = info.compCompHnd->getArgNext(argLst);
1014954
}
1015955
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
8+
</dependentAssembly>
9+
<dependentAssembly>
10+
<assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
12+
</dependentAssembly>
13+
<dependentAssembly>
14+
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
15+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
16+
</dependentAssembly>
17+
<dependentAssembly>
18+
<assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
19+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
20+
</dependentAssembly>
21+
<dependentAssembly>
22+
<assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
23+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
24+
</dependentAssembly>
25+
</assemblyBinding>
26+
</runtime>
27+
</configuration>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
// When the jit considers inlining B it can get itself into
6+
// trouble because of the type mismatch. This test tries to
7+
// ensure the jit backs out of the inline successfully.
8+
9+
.assembly extern mscorlib { }
10+
.assembly extern System.Console
11+
{
12+
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
13+
.ver 4:0:0:0
14+
}
15+
.assembly main {}
16+
.module main.exe
17+
18+
.class public sealed F extends System.ValueType
19+
{
20+
21+
.method public instance void .ctor()
22+
{
23+
ret
24+
}
25+
26+
.field public string A
27+
}
28+
29+
.method private static int32 B(int32 X, int32 Y)
30+
{
31+
ldarg.0
32+
ret
33+
}
34+
35+
.method public hidebysig static int32 Main(string[] args) cil managed
36+
{
37+
.entrypoint
38+
.locals init (valuetype F v_0)
39+
ldarg.0
40+
ldlen
41+
ldc.i4 1
42+
bgt DONE
43+
newobj instance void F::.ctor()
44+
ldc.i4 33
45+
call int32 B(int32, int32)
46+
pop
47+
48+
DONE:
49+
50+
ldc.i4 100
51+
ret
52+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16+
<RestorePackages>true</RestorePackages>
17+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
18+
</PropertyGroup>
19+
<!-- Default configurations to help VS understand the configurations -->
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
</PropertyGroup>
24+
<ItemGroup>
25+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
26+
<Visible>False</Visible>
27+
</CodeAnalysisDependentAssemblyPaths>
28+
</ItemGroup>
29+
<PropertyGroup>
30+
</PropertyGroup>
31+
<ItemGroup>
32+
<Compile Include="mismatch32.il" />
33+
</ItemGroup>
34+
<ItemGroup>
35+
<None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" />
36+
<None Include="app.config" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
40+
</ItemGroup>
41+
<PropertyGroup>
42+
<ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
43+
<ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
44+
</PropertyGroup>
45+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
46+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
47+
</PropertyGroup>
48+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
8+
</dependentAssembly>
9+
<dependentAssembly>
10+
<assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
12+
</dependentAssembly>
13+
<dependentAssembly>
14+
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
15+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
16+
</dependentAssembly>
17+
<dependentAssembly>
18+
<assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
19+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
20+
</dependentAssembly>
21+
<dependentAssembly>
22+
<assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
23+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
24+
</dependentAssembly>
25+
</assemblyBinding>
26+
</runtime>
27+
</configuration>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
// When the jit considers inlining B it can get itself into
6+
// trouble because of the type mismatch. This test tries to
7+
// ensure the jit backs out of the inline successfully.
8+
9+
.assembly extern mscorlib { }
10+
.assembly extern System.Console
11+
{
12+
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
13+
.ver 4:0:0:0
14+
}
15+
.assembly main {}
16+
.module main.exe
17+
18+
.class public sealed F extends System.ValueType
19+
{
20+
21+
.method public instance void .ctor()
22+
{
23+
ret
24+
}
25+
26+
.field public string A
27+
}
28+
29+
.method private static int64 B(int64 X, int64 Y)
30+
{
31+
ldarg.0
32+
ret
33+
}
34+
35+
.method public hidebysig static int32 Main(string[] args) cil managed
36+
{
37+
.entrypoint
38+
.locals init (valuetype F v_0)
39+
ldarg.0
40+
ldlen
41+
ldc.i4 1
42+
bgt DONE
43+
newobj instance void F::.ctor()
44+
ldc.i8 44
45+
call int64 B(int64, int64)
46+
pop
47+
48+
DONE:
49+
50+
ldc.i4 100
51+
ret
52+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16+
<RestorePackages>true</RestorePackages>
17+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
18+
</PropertyGroup>
19+
<!-- Default configurations to help VS understand the configurations -->
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
</PropertyGroup>
24+
<ItemGroup>
25+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
26+
<Visible>False</Visible>
27+
</CodeAnalysisDependentAssemblyPaths>
28+
</ItemGroup>
29+
<PropertyGroup>
30+
</PropertyGroup>
31+
<ItemGroup>
32+
<Compile Include="mismatch64.il" />
33+
</ItemGroup>
34+
<ItemGroup>
35+
<None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" />
36+
<None Include="app.config" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
40+
</ItemGroup>
41+
<PropertyGroup>
42+
<ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
43+
<ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
44+
</PropertyGroup>
45+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
46+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
47+
</PropertyGroup>
48+
</Project>

0 commit comments

Comments
 (0)