diff options
author | Richard L Ford <richford@microsoft.com> | 2015-12-03 00:23:02 -0800 |
---|---|---|
committer | Richard L Ford <richford@microsoft.com> | 2015-12-07 20:50:02 -0800 |
commit | 99570b16c3a852abc18706c336103c5352f41ba2 (patch) | |
tree | 42c28d2fc2c53d65c5ec59aee97553f67c8f9c07 /tests/src/JIT/jit64/rtchecks | |
parent | 01fdf5036c24468185e7b6f01976100424183be2 (diff) | |
download | coreclr-99570b16c3a852abc18706c336103c5352f41ba2.tar.gz coreclr-99570b16c3a852abc18706c336103c5352f41ba2.tar.bz2 coreclr-99570b16c3a852abc18706c336103c5352f41ba2.zip |
Port more C# unit tests
The project files were generated automatically from a database
and the source files scrubbed and formatted.
In addition, some added tests are still failing. Issues were
created for these and exclusions added, for windows and for
non-windows.
Diffstat (limited to 'tests/src/JIT/jit64/rtchecks')
21 files changed, 2128 insertions, 0 deletions
diff --git a/tests/src/JIT/jit64/rtchecks/overflow/app.config b/tests/src/JIT/jit64/rtchecks/overflow/app.config new file mode 100644 index 0000000000..6f7bbd9d2b --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/app.config @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow01.cs b/tests/src/JIT/jit64/rtchecks/overflow/overflow01.cs new file mode 100644 index 0000000000..687dee1bc9 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow01.cs @@ -0,0 +1,265 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +internal class OVFTest +{ + static public volatile bool rtv; + + static OVFTest() + { + rtv = Environment.TickCount != 0; + } + + private static sbyte Test_sbyte(sbyte a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (sbyte)(a / 0.5); +#elif OP_ADD + return (sbyte)(a + a); +#elif OP_SUB + return (sbyte)(-1 - a - a); +#else + return (sbyte)(a * 2); +#endif + } + } + + private static byte Test_byte(byte a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (byte)(a / 0.5); +#elif OP_ADD + return (byte)(a + a); +#elif OP_SUB + return (byte)(0 - a - a); +#else + return (byte)(a * 2); +#endif + } + } + + private static short Test_short(short a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (short)(a / 0.5); +#elif OP_ADD + return (short)(a + a); +#elif OP_SUB + return (short)(-1 - a - a); +#else + return (short)(a * 2); +#endif + } + } + + private static ushort Test_ushort(ushort a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (ushort)(a / 0.5); +#elif OP_ADD + return (ushort)(a + a); +#elif OP_SUB + return (ushort)(0 - a - a); +#else + return (ushort)(a * 2); +#endif + } + } + + private static int Test_int(int a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (int)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return -1 - a - a; +#else + return a * 2; +#endif + } + } + + private static uint Test_uint(uint a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (uint)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return 0U - a - a; +#else + return a * 2; +#endif + } + } + + private static long Test_long(long a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (long)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return -1L - a - a; +#else + return a * 2; +#endif + } + } + + private static ulong Test_ulong(ulong a) + { + if (!rtv) return 0; + checked + { +#if OP_DIV + return (ulong)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return 0UL - a - a; +#else + return a * 2; +#endif + } + } + + private static int Main(string[] args) + { +#if OP_DIV + const string op = "div.ovf"; +#elif OP_ADD + const string op = "add.ovf"; +#elif OP_SUB + const string op = "sub.ovf"; +#else + const string op = "mul.ovf"; +#endif + + Console.WriteLine("Runtime Checks [OP: {0}]", op); + + int check = 8; + + try + { + Console.Write("Type 'byte' . . : "); + byte a = Test_byte((byte)(OVFTest.rtv ? 1 + byte.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'sbyte'. . : "); + sbyte a = Test_sbyte((sbyte)(OVFTest.rtv ? 1 + sbyte.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'short'. . : "); + short a = Test_short((short)(OVFTest.rtv ? 1 + short.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ushort' . : "); + ushort a = Test_ushort((ushort)(OVFTest.rtv ? 1 + ushort.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'int'. . . : "); + int a = Test_int((int)(OVFTest.rtv ? 1 + int.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'uint' . . : "); + uint a = Test_uint((uint)(OVFTest.rtv ? 1U + uint.MaxValue / 2U : 0U)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'long' . . : "); + long a = Test_long((long)(OVFTest.rtv ? 1L + long.MaxValue / 2L : 0L)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ulong'. . : "); + ulong a = Test_ulong((ulong)(OVFTest.rtv ? 1UL + ulong.MaxValue / 2UL : 0UL)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + return check == 0 ? 100 : 1; + } +} diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow01_add.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_add.csproj new file mode 100644 index 0000000000..c399fecf9b --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_add.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_ADD</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow01.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow01_div.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_div.csproj new file mode 100644 index 0000000000..139a2e34f9 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_div.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_DIV</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow01.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow01_mul.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_mul.csproj new file mode 100644 index 0000000000..e11da73ca5 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_mul.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_MUL</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow01.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow01_sub.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_sub.csproj new file mode 100644 index 0000000000..3b3ff2c17f --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow01_sub.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_SUB</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow01.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow02.cs b/tests/src/JIT/jit64/rtchecks/overflow/overflow02.cs new file mode 100644 index 0000000000..eb93908fde --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow02.cs @@ -0,0 +1,273 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +internal class OVFTest +{ + static public volatile bool rtv; + + static OVFTest() + { + rtv = Environment.TickCount != 0; + } + + private static sbyte Test_sbyte() + { + if (!rtv) return 0; + sbyte a = 1 + sbyte.MaxValue / 2; + checked + { +#if OP_DIV + return (sbyte)(a / 0.5); +#elif OP_ADD + return (sbyte)(a + a); +#elif OP_SUB + return (sbyte)(-1 - a - a); +#else + return (sbyte)(a * 2); +#endif + } + } + + private static byte Test_byte() + { + if (!rtv) return 0; + byte a = 1 + byte.MaxValue / 2; + checked + { +#if OP_DIV + return (byte)(a / 0.5); +#elif OP_ADD + return (byte)(a + a); +#elif OP_SUB + return (byte)(0 - a - a); +#else + return (byte)(a * 2); +#endif + } + } + + private static short Test_short() + { + if (!rtv) return 0; + short a = 1 + short.MaxValue / 2; + checked + { +#if OP_DIV + return (short)(a / 0.5); +#elif OP_ADD + return (short)(a + a); +#elif OP_SUB + return (short)(-1 - a - a); +#else + return (short)(a * 2); +#endif + } + } + + private static ushort Test_ushort() + { + if (!rtv) return 0; + ushort a = 1 + ushort.MaxValue / 2; + checked + { +#if OP_DIV + return (ushort)(a / 0.5); +#elif OP_ADD + return (ushort)(a + a); +#elif OP_SUB + return (ushort)(0 - a - a); +#else + return (ushort)(a * 2); +#endif + } + } + + private static int Test_int() + { + if (!rtv) return 0; + int a = 1 + int.MaxValue / 2; + checked + { +#if OP_DIV + return (int)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return -1 - a - a; +#else + return a * 2; +#endif + } + } + + private static uint Test_uint() + { + if (!rtv) return 0; + uint a = 1U + uint.MaxValue / 2U; + checked + { +#if OP_DIV + return (uint)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return 0U - a - a; +#else + return a * 2; +#endif + } + } + + private static long Test_long() + { + if (!rtv) return 0; + long a = 1L + long.MaxValue / 2L; + checked + { +#if OP_DIV + return (long)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return -1L - a - a; +#else + return a * 2; +#endif + } + } + + private static ulong Test_ulong() + { + if (!rtv) return 0; + ulong a = 1UL + ulong.MaxValue / 2UL; + checked + { +#if OP_DIV + return (ulong)(a / 0.5); +#elif OP_ADD + return a + a; +#elif OP_SUB + return 0UL - a - a; +#else + return a * 2; +#endif + } + } + + private static int Main(string[] args) + { +#if OP_DIV + const string op = "div.ovf"; +#elif OP_ADD + const string op = "add.ovf"; +#elif OP_SUB + const string op = "sub.ovf"; +#else + const string op = "mul.ovf"; +#endif + + Console.WriteLine("Runtime Checks [OP: {0}]", op); + + int check = 8; + + try + { + Console.Write("Type 'byte' . . : "); + byte a = Test_byte(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'sbyte'. . : "); + sbyte a = Test_sbyte(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'short'. . : "); + short a = Test_short(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ushort' . : "); + ushort a = Test_ushort(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'int'. . . : "); + int a = Test_int(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'uint' . . : "); + uint a = Test_uint(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'long' . . : "); + long a = Test_long(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ulong'. . : "); + ulong a = Test_ulong(); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + return check == 0 ? 100 : 1; + } +} diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow02_add.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_add.csproj new file mode 100644 index 0000000000..5a14cf0c20 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_add.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_ADD</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow02.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow02_div.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_div.csproj new file mode 100644 index 0000000000..b420caf956 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_div.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_DIV</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow02.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow02_mul.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_mul.csproj new file mode 100644 index 0000000000..2bcffb4680 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_mul.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_MUL</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow02.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow02_sub.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_sub.csproj new file mode 100644 index 0000000000..7c38751a8f --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow02_sub.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_SUB</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow02.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow03.cs b/tests/src/JIT/jit64/rtchecks/overflow/overflow03.cs new file mode 100644 index 0000000000..21c9f1404f --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow03.cs @@ -0,0 +1,441 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +internal class OVFTest +{ + static public volatile bool rtv; + + static OVFTest() + { + rtv = Environment.TickCount != 0; + } + + private static sbyte Test_sbyte(sbyte a) + { + try + { + checked + { +#if OP_DIV + a = (sbyte)(a / 0.5); +#elif OP_ADD + a = (sbyte)(a + a); +#elif OP_SUB + a = (sbyte)(-1 - a - a); +#else + a = (sbyte)(a * 2); +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (sbyte)(a / 0.5); +#elif OP_ADD + a = (sbyte)(a + a); +#elif OP_SUB + a = (sbyte)(-1 - a - a); +#else + a = (sbyte)(a * 2); +#endif + } + } + } + + private static byte Test_byte(byte a) + { + try + { + checked + { +#if OP_DIV + a = (byte)(a / 0.5); +#elif OP_ADD + a = (byte)(a + a); +#elif OP_SUB + a = (byte)(0 - a - a); +#else + a = (byte)(a * 2); +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (byte)(a / 0.5); +#elif OP_ADD + a = (byte)(a + a); +#elif OP_SUB + a = (byte)(0 - a - a); +#else + a = (byte)(a * 2); +#endif + } + } + } + + private static short Test_short(short a) + { + try + { + checked + { +#if OP_DIV + a = (short)(a / 0.5); +#elif OP_ADD + a = (short)(a + a); +#elif OP_SUB + a = (short)(-1 - a - a); +#else + a = (short)(a * 2); +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (short)(a / 0.5); +#elif OP_ADD + a = (short)(a + a); +#elif OP_SUB + a = (short)(-1 - a - a); +#else + a = (short)(a * 2); +#endif + } + } + } + + private static ushort Test_ushort(ushort a) + { + try + { + checked + { +#if OP_DIV + a = (ushort)(a / 0.5); +#elif OP_ADD + a = (ushort)(a + a); +#elif OP_SUB + a = (ushort)(0 - a - a); +#else + a = (ushort)(a * 2); +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (ushort)(a / 0.5); +#elif OP_ADD + a = (ushort)(a + a); +#elif OP_SUB + a = (ushort)(0 - a - a); +#else + a = (ushort)(a * 2); +#endif + } + } + } + + private static int Test_int(int a) + { + try + { + checked + { +#if OP_DIV + a = (int)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = -1 - a - a; +#else + a = a * 2; +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (int)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = -1 - a - a; +#else + a = a * 2; +#endif + } + } + } + + private static uint Test_uint(uint a) + { + try + { + checked + { +#if OP_DIV + a = (uint)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = 0U - a - a; +#else + a = a * 2U; +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (uint)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = 0U - a - a; +#else + a = a * 2U; +#endif + } + } + } + + private static long Test_long(long a) + { + try + { + checked + { +#if OP_DIV + a = (long)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = -1L - a - a; +#else + a = a * 2L; +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (long)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = -1L - a - a; +#else + a = a * 2L; +#endif + } + } + } + + private static ulong Test_ulong(ulong a) + { + try + { + checked + { +#if OP_DIV + a = (ulong)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = 0UL - a - a; +#else + a = a * 2UL; +#endif + return a; + } + } + catch (System.OverflowException) + { + return a; + } + finally + { + checked + { +#if OP_DIV + a = (ulong)(a / 0.5); +#elif OP_ADD + a = a + a; +#elif OP_SUB + a = 0UL - a - a; +#else + a = a * 2UL; +#endif + } + } + } + + private static int Main(string[] args) + { +#if OP_DIV + const string op = "div.ovf"; +#elif OP_ADD + const string op = "add.ovf"; +#elif OP_SUB + const string op = "sub.ovf"; +#else + const string op = "mul.ovf"; +#endif + + Console.WriteLine("Runtime Checks [OP: {0}]", op); + + int check = 8; + + try + { + Console.Write("Type 'byte' . . : "); + byte a = Test_byte((byte)(OVFTest.rtv ? 1 + byte.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'sbyte'. . : "); + sbyte a = Test_sbyte((sbyte)(OVFTest.rtv ? 1 + sbyte.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'short'. . : "); + short a = Test_short((short)(OVFTest.rtv ? 1 + short.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ushort' . : "); + ushort a = Test_ushort((ushort)(OVFTest.rtv ? 1 + ushort.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'int'. . . : "); + int a = Test_int((int)(OVFTest.rtv ? 1 + int.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'uint' . . : "); + uint a = Test_uint((uint)(OVFTest.rtv ? 1U + uint.MaxValue / 2U : 0U)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'long' . . : "); + long a = Test_long((long)(OVFTest.rtv ? 1L + long.MaxValue / 2L : 0L)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ulong'. . : "); + ulong a = Test_ulong((ulong)(OVFTest.rtv ? 1UL + ulong.MaxValue / 2UL : 0UL)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + return check == 0 ? 100 : 1; + } +} diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow03_add.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_add.csproj new file mode 100644 index 0000000000..d0d2b2b696 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_add.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_ADD</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow03.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow03_div.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_div.csproj new file mode 100644 index 0000000000..84fbef9fa0 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_div.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_DIV</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow03.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow03_mul.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_mul.csproj new file mode 100644 index 0000000000..e93b1e3168 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_mul.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_MUL</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow03.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow03_sub.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_sub.csproj new file mode 100644 index 0000000000..434099ad60 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow03_sub.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_SUB</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow03.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow04.cs b/tests/src/JIT/jit64/rtchecks/overflow/overflow04.cs new file mode 100644 index 0000000000..cddd838679 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow04.cs @@ -0,0 +1,258 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +internal class OVFTest +{ + static public volatile bool rtv; + + static OVFTest() + { + rtv = Environment.TickCount != 0; + } + + private static sbyte Test_sbyte(sbyte a) + { + checked + { +#if OP_DIV + return Test_sbyte((sbyte)(a / 0.5)); +#elif OP_ADD + return Test_sbyte((sbyte)(a + a)); +#elif OP_SUB + return Test_sbyte((sbyte)(-1 - a - a)); +#else + return Test_sbyte((sbyte)(a * 2)); +#endif + } + } + + private static byte Test_byte(byte a) + { + checked + { +#if OP_DIV + return Test_byte((byte)(a / 0.5)); +#elif OP_ADD + return Test_byte((byte)(a + a)); +#elif OP_SUB + return Test_byte((byte)(0 - a - a)); +#else + return Test_byte((byte)(a * 2)); +#endif + } + } + + private static short Test_short(short a) + { + checked + { +#if OP_DIV + return Test_short((short)(a / 0.5)); +#elif OP_ADD + return Test_short((short)(a + a)); +#elif OP_SUB + return Test_short((short)(-1 - a - a)); +#else + return Test_short((short)(a * 2)); +#endif + } + } + + private static ushort Test_ushort(ushort a) + { + checked + { +#if OP_DIV + return Test_ushort((ushort)(a / 0.5)); +#elif OP_ADD + return Test_ushort((ushort)(a + a)); +#elif OP_SUB + return Test_ushort((ushort)(0 - a - a)); +#else + return Test_ushort((ushort)(a * 2)); +#endif + } + } + + private static int Test_int(int a) + { + checked + { +#if OP_DIV + return Test_int((int)(a / 0.5)); +#elif OP_ADD + return Test_int(a + a); +#elif OP_SUB + return Test_int(-1 - a - a); +#else + return Test_int(a * 2); +#endif + } + } + + private static uint Test_uint(uint a) + { + checked + { +#if OP_DIV + return Test_uint((uint)(a / 0.5)); +#elif OP_ADD + return Test_uint(a + a); +#elif OP_SUB + return Test_uint(0U - a - a); +#else + return Test_uint(a * 2U); +#endif + } + } + + private static long Test_long(long a) + { + checked + { +#if OP_DIV + return Test_long((long)(a / 0.5)); +#elif OP_ADD + return Test_long(a + a); +#elif OP_SUB + return Test_long(-1L - a - a); +#else + return Test_long(a * 2L); +#endif + } + } + + private static ulong Test_ulong(ulong a) + { + checked + { +#if OP_DIV + return Test_ulong((ulong)(a / 0.5)); +#elif OP_ADD + return Test_ulong(a + a); +#elif OP_SUB + return Test_ulong(0UL - a - a); +#else + return Test_ulong(a * 2UL); +#endif + } + } + + + private static int Main(string[] args) + { +#if OP_DIV + const string op = "div.ovf"; +#elif OP_ADD + const string op = "add.ovf"; +#elif OP_SUB + const string op = "sub.ovf"; +#else + const string op = "mul.ovf"; +#endif + + Console.WriteLine("Runtime Checks [OP: {0}]", op); + + int check = 8; + + try + { + Console.Write("Type 'byte' . . : "); + byte a = Test_byte((byte)(OVFTest.rtv ? 1 + byte.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'sbyte'. . : "); + sbyte a = Test_sbyte((sbyte)(OVFTest.rtv ? 1 + sbyte.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'short'. . : "); + short a = Test_short((short)(OVFTest.rtv ? 1 + short.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ushort' . : "); + ushort a = Test_ushort((ushort)(OVFTest.rtv ? 1 + ushort.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'int'. . . : "); + int a = Test_int((int)(OVFTest.rtv ? 1 + int.MaxValue / 2 : 0)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'uint' . . : "); + uint a = Test_uint((uint)(OVFTest.rtv ? 1U + uint.MaxValue / 2U : 0U)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'long' . . : "); + long a = Test_long((long)(OVFTest.rtv ? 1L + long.MaxValue / 2L : 0L)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + try + { + Console.Write("Type 'ulong'. . : "); + ulong a = Test_ulong((ulong)(OVFTest.rtv ? 1UL + ulong.MaxValue / 2UL : 0UL)); + Console.WriteLine("failed! - a = " + a); + } + catch (System.OverflowException) + { + Console.WriteLine("passed"); + check--; + } + + return check == 0 ? 100 : 1; + } +} diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow04_add.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_add.csproj new file mode 100644 index 0000000000..e71fe02491 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_add.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_ADD</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow04.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow04_div.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_div.csproj new file mode 100644 index 0000000000..329ca7cfb6 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_div.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_DIV</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow04.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow04_mul.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_mul.csproj new file mode 100644 index 0000000000..67782a3a05 --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_mul.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_MUL</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow04.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/jit64/rtchecks/overflow/overflow04_sub.csproj b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_sub.csproj new file mode 100644 index 0000000000..882b44dffa --- /dev/null +++ b/tests/src/JIT/jit64/rtchecks/overflow/overflow04_sub.csproj @@ -0,0 +1,54 @@ +<?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 .0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <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> + <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> + <DebugType></DebugType> + <NoLogo>True</NoLogo> + <NoStandardLib>True</NoStandardLib> + <Noconfig>True</Noconfig> + <DefineConstants>$(DefineConstants);CORECLR;OP_SUB</DefineConstants> + </PropertyGroup> + <ItemGroup> + <Compile Include="overflow04.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)minimal\project.json" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> |