diff options
Diffstat (limited to 'tests/src/JIT/Directed/Misc/SIDEEFFECTS')
4 files changed, 509 insertions, 0 deletions
diff --git a/tests/src/JIT/Directed/Misc/SIDEEFFECTS/BadRegArgs.il b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/BadRegArgs.il new file mode 100644 index 0000000000..355685f409 --- /dev/null +++ b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/BadRegArgs.il @@ -0,0 +1,156 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern legacy library mscorlib {} +.assembly extern System.Console +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) + .ver 4:0:0:0 +} +.assembly badregargs +{ +} +// Original test by sborde modified by bwadswor +.class BadRegArgs +{ + .field public static int32 s_i + .field public static class [mscorlib]System.Object s_Obj + + .method public static int32 foo1(int32 a, int32 b) il managed + { + .locals(int32) + + call void [System.Console]System.Console::WriteLine() + + ldarg a // a += s_i + ldsfld int32 BadRegArgs::s_i + add + starg a + + ldstr "Should print 100 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + ldarg a + call void [System.Console]System.Console::WriteLine(int32) + + ldarg a + ldc.i4 100 + bne.un ERR_EXIT + + + ldsfld int32 BadRegArgs::s_i // b = s_i; So b is DEAD on entry + starg b + + ldarg b // b += s_i + ldsfld int32 BadRegArgs::s_i + add + starg b + + ldstr "Should print 0 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + ldarg b + call void [System.Console]System.Console::WriteLine(int32) + ldarg b + ldc.i4 0 + bne.un ERR_EXIT + ldc.i4 0 + ret + +ERR_EXIT: + ldc.i4 1 + ret + + } + + + .method public static int32 foo2(int32 a, int32 b) il managed + { + .locals(int32 temp, + class [mscorlib]System.Object obj1, + class [mscorlib]System.Object obj2, + class [mscorlib]System.Object obj3, + class [mscorlib]System.Object obj4, + class [mscorlib]System.Object obj5, + class [mscorlib]System.Object obj6) + + ldloca obj1 + pop + ldloc obj1 + stsfld class [mscorlib]System.Object BadRegArgs::s_Obj + + ldloca obj2 + pop + ldloc obj2 + stsfld class [mscorlib]System.Object BadRegArgs::s_Obj + + ldloca obj3 + pop + ldloc obj3 + stsfld class [mscorlib]System.Object BadRegArgs::s_Obj + + ldloca obj4 + pop + ldloc obj4 + stsfld class [mscorlib]System.Object BadRegArgs::s_Obj + + ldloca obj5 + pop + ldloc obj5 + stsfld class [mscorlib]System.Object BadRegArgs::s_Obj + + ldloca obj6 + pop + ldloc obj6 + stsfld class [mscorlib]System.Object BadRegArgs::s_Obj + + ldarg a + ldarg b + add + stloc temp + + ldstr "Should print 300 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + ldloc temp + call void [System.Console]System.Console::WriteLine(int32) + + ldloc temp + ldc.i4 300 + bne.un ERR_EXIT + + ldc.i4 0 + ret + +ERR_EXIT: + ldc.i4 1 + ret + + } + +//---------------------------------------------------------------------------- + + + .method public static int32 main(class [mscorlib]System.String[] A_0) il managed + { + .entrypoint + .maxstack 10 + .locals (int32,int32,int32) + + + ldc.i4 100 + ldc.i4 200 + call int32 BadRegArgs::foo1(int32, int32) + + ldc.i4 100 + ldc.i4 200 + call int32 BadRegArgs::foo2(int32, int32) + + add + + ldc.i4 0x64 + add + + ret + } + +} + diff --git a/tests/src/JIT/Directed/Misc/SIDEEFFECTS/BadRegArgs.ilproj b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/BadRegArgs.ilproj new file mode 100644 index 0000000000..3a1fab97b6 --- /dev/null +++ b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/BadRegArgs.ilproj @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>$(MSBuildProjectName)</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + + </PropertyGroup> + <ItemGroup> + <Compile Include="BadRegArgs.il" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/tests/src/JIT/Directed/Misc/SIDEEFFECTS/SideEffects.il b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/SideEffects.il new file mode 100644 index 0000000000..02ad880b19 --- /dev/null +++ b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/SideEffects.il @@ -0,0 +1,273 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern legacy library mscorlib {} +.assembly extern System.Console +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) + .ver 4:0:0:0 +} +.assembly sideeffects +{ +} +.class SideEffects +{ + .field public static int32 m_i + .field public static int32 s_i + .field public static value class [mscorlib]System.Decimal s_d + +//---------------------------------------------------------------------------- + + .method public static int32 AliasedLocal() il managed + { + .locals(int32 aliasedLocal, int32 & addrOfLocal, int32 temp) + + ldsfld int32 SideEffects::s_i // aliasedLocal = 0 + stloc aliasedLocal + + ldloca aliasedLocal // addrOfLocal = &aliasedLocal + stloc addrOfLocal + + ldloc aliasedLocal // push aliasedLocal + + ldloc addrOfLocal // *addrOfLocal = 5 + ldc.i4 5 + stind.i4 + + stloc temp // temp = pushed alisasedLocal + + ldstr "Should print 0 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + + ldloc temp + call void [System.Console]System.Console::WriteLine(int32) + + ldloc temp + ldc.i4 0 + bne.un ERROR_EXIT + ldc.i4 0 + ret +ERROR_EXIT: + ldc.i4 1 + ret + } + + +//---------------------------------------------------------------------------- + + .method public static void AliasedLocalCall_helper(int32 & addrOfLocal) il managed + { + .try // to avoid inlining + { + ldarg addrOfLocal // *addrOfLocal = 5 + ldc.i4 5 + stind.i4 + leave DONE + } + catch [mscorlib]System.Exception + { + pop + newobj instance void [mscorlib]System.Exception::.ctor() + throw + } +DONE: + ret + } + + .method public static int32 AliasedLocalCall() il managed + { + .locals(int32 aliasedLocal, int32 & addrOfLocal, int32 temp) + + ldsfld int32 SideEffects::s_i // aliasedLocal = 0 + stloc aliasedLocal + + ldloca aliasedLocal // addrOfLocal = &aliasedLocal + stloc addrOfLocal + + ldloc aliasedLocal // push aliasedLocal + + ldloc addrOfLocal // AliasedLocalCall_helper(addrOfLocal) + call void SideEffects::AliasedLocalCall_helper(int32&) + + stloc temp // temp = pushed alisasedLocal + + ldstr "Should print 0 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + + ldloc temp + call void [System.Console]System.Console::WriteLine(int32) + + ldloc temp + ldc.i4 0 + bne.un ERROR_EXIT + ldc.i4 0 + ret +ERROR_EXIT: + ldc.i4 1 + ret + } + +//---------------------------------------------------------------------------- + + .method public static int32 AliasedLocalIndir() il managed + { + .locals(int32 aliasedLocal, int32 & addrOfLocal, int32 temp) + + ldsfld int32 SideEffects::s_i // aliasedLocal = 0 + stloc aliasedLocal + + ldloca aliasedLocal // addrOfLocal = &aliasedLocal + stloc addrOfLocal + + ldloc addrOfLocal // push *addrOfLocal + ldind.i4 + + ldloc addrOfLocal // *addrOfLocal = 5 + ldc.i4 5 + stind.i4 + + stloc temp // temp = pushed *addrOfLocal + + ldstr "Should print 0 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + + ldloc temp + call void [System.Console]System.Console::WriteLine(int32) + + ldloc temp + ldc.i4 0 + bne.un ERROR_EXIT + ldc.i4 0 + ret +ERROR_EXIT: + ldc.i4 1 + ret + } + +//---------------------------------------------------------------------------- + + .method public static int32 AliasedStatic() il managed + { + .locals(int32 & addrOfStatic, int32 temp) + + ldsflda int32 SideEffects::s_i // addrOfStatic = &si + stloc addrOfStatic + + ldsfld int32 SideEffects::s_i // push s_i + + ldloc addrOfStatic // *addrOfStatic = 5 + ldc.i4 5 + stind.i4 + + stloc temp // temp = pushed s_i + + ldstr "Should print 0 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + + ldloc temp + call void [System.Console]System.Console::WriteLine(int32) + ldloc temp + ldc.i4 0 + bne.un ERROR_EXIT + ldc.i4 0 + ret +ERROR_EXIT: + ldc.i4 1 + ret + } + +//---------------------------------------------------------------------------- + + .method public static void SpillStatic_helper() il managed + { + .try // to avoid inlining + { + ldc.i4 5 // s_i = 5 + stsfld int32 SideEffects::s_i + leave DONE + } + catch [mscorlib]System.Exception + { + pop + newobj instance void [mscorlib]System.Exception::.ctor() + throw + } +DONE: + ret + } + + .method public static int32 SpillStatic() il managed + { + .locals(int32 & addrOfStatic, int32 temp) + + ldsfld int32 SideEffects::s_i // push s_i + + call void SideEffects::SpillStatic_helper() + + stloc temp // temp = pushed s_i + + ldstr "Should print 0 : " + call void [System.Console]System.Console::Write(class [mscorlib]System.String) + + ldloc temp + call void [System.Console]System.Console::WriteLine(int32) + + ldloc temp + ldc.i4 0 + bne.un ERROR_EXIT + ldc.i4 0 + ret +ERROR_EXIT: + ldc.i4 1 + ret + } + + +//---------------------------------------------------------------------------- + + + .method public static int32 main(class [mscorlib]System.String[] A_0) il managed + { + .entrypoint + .maxstack 10 + .locals (int32,int32,int32) + + ldc.i4 0 + stsfld int32 SideEffects::s_i + call int32 SideEffects::AliasedLocal() + + ldc.i4 0 + stsfld int32 SideEffects::s_i + call int32 SideEffects::AliasedLocalCall() + + ldc.i4 0 + stsfld int32 SideEffects::s_i + call int32 SideEffects::AliasedLocalIndir() + + ldc.i4 0 + stsfld int32 SideEffects::s_i + call int32 SideEffects::AliasedStatic() + + ldc.i4 0 + stsfld int32 SideEffects::s_i + call int32 SideEffects::SpillStatic() +add +add +add +add + ldc.i4 0x64 + add + ret + } + + .method public specialname rtspecialname instance void .ctor(int32) il managed + { + ldarg 0 + ldc.i4 555 + stfld int32 SideEffects::m_i + ret + } + +} + diff --git a/tests/src/JIT/Directed/Misc/SIDEEFFECTS/SideEffects.ilproj b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/SideEffects.ilproj new file mode 100644 index 0000000000..16ced7c7ee --- /dev/null +++ b/tests/src/JIT/Directed/Misc/SIDEEFFECTS/SideEffects.ilproj @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>$(MSBuildProjectName)</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + + </PropertyGroup> + <ItemGroup> + <Compile Include="SideEffects.il" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project>
\ No newline at end of file |