diff options
author | Bruce Forstall <brucefo@microsoft.com> | 2017-05-05 07:24:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-05 07:24:49 -0700 |
commit | f3bf62697c63e1bc4c383b9af82d0d3e42ac2afd (patch) | |
tree | d3b759eeef9e9a5a71d2994090fe60d9e27e247e | |
parent | f1b1172f132acb9a6d8280eb9088ce52868c8956 (diff) | |
parent | 331c37eb26ca29413dffe6997d5514492d5dbba8 (diff) | |
download | coreclr-f3bf62697c63e1bc4c383b9af82d0d3e42ac2afd.tar.gz coreclr-f3bf62697c63e1bc4c383b9af82d0d3e42ac2afd.tar.bz2 coreclr-f3bf62697c63e1bc4c383b9af82d0d3e42ac2afd.zip |
Merge pull request #11361 from mikedn/imp-strlen-except
Add missing GTF_EXCEPT when importing string length intrinsic
-rw-r--r-- | src/jit/importer.cpp | 4 | ||||
-rw-r--r-- | tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.cs | 33 | ||||
-rw-r--r-- | tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.csproj | 42 |
3 files changed, 79 insertions, 0 deletions
diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index 9737c136f7..c2e2cfaf94 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -3526,6 +3526,10 @@ GenTreePtr Compiler::impIntrinsic(GenTreePtr newobjThis, gtNewIconNode(offsetof(CORINFO_String, stringLen), TYP_I_IMPL)); op1 = gtNewOperNode(GT_IND, TYP_INT, op1); } + + // Getting the length of a null string should throw + op1->gtFlags |= GTF_EXCEPT; + retNode = op1; break; diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.cs b/tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.cs new file mode 100644 index 0000000000..e23d9fc76c --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.cs @@ -0,0 +1,33 @@ +// 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. + +using System; +using System.Runtime.CompilerServices; + +class GitHub_11343 +{ + const int Passed = 100; + const int Failed = 0; + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test() + { + string s = null; + // Should throw NullReferenceException even if the result is not used + int unused = s.Length; + } + + static int Main() + { + try + { + Test(); + return Failed; + } + catch (NullReferenceException) + { + return Passed; + } + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.csproj new file mode 100644 index 0000000000..c493c4ed35 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_11343/GitHub_11343.csproj @@ -0,0 +1,42 @@ +<?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> + <DebugType></DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Compile Include="GitHub_11343.cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> |