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

Commit

Permalink
Fix incorrect switch temp lcl type
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedn committed Aug 19, 2017
1 parent 5dada64 commit d93735c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
assert(temp->gtOper == GT_LCL_VAR);
unsigned tempLclNum = temp->gtLclVarCommon.gtLclNum;
LclVarDsc* tempVarDsc = comp->lvaTable + tempLclNum;
var_types tempLclType = tempVarDsc->TypeGet();
var_types tempLclType = temp->TypeGet();

BasicBlock* defaultBB = jumpTab[jumpCnt - 1];
BasicBlock* followingBB = originalSwitchBB->bbNext;
Expand Down Expand Up @@ -548,7 +548,7 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
// both GT_SWITCH lowering code paths.
// This condition is of the form: if (temp > jumpTableLength - 2){ goto jumpTable[jumpTableLength - 1]; }
GenTreePtr gtDefaultCaseCond = comp->gtNewOperNode(GT_GT, TYP_INT, comp->gtNewLclvNode(tempLclNum, tempLclType),
comp->gtNewIconNode(jumpCnt - 2, tempLclType));
comp->gtNewIconNode(jumpCnt - 2, genActualType(tempLclType)));

// Make sure we perform an unsigned comparison, just in case the switch index in 'temp'
// is now less than zero 0 (that would also hit the default case).
Expand Down
33 changes: 33 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_13486/GitHub_13486.cs
Original file line number Diff line number Diff line change
@@ -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 Program
{
enum LongEnum : long
{
Option0, Option1, Option2
}

[MethodImpl(MethodImplOptions.NoInlining)]
static string Test(LongEnum v)
{
string s;
switch (v)
{
case LongEnum.Option0: s = "Option0"; break;
case LongEnum.Option1: s = "Option1"; break;
case LongEnum.Option2: s = "Option2"; break;
default: throw new Exception();
}
return s;
}

static int Main()
{
return (Test(LongEnum.Option0) == "Option0") ? 100 : 1;
}
}
25 changes: 25 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_13486/GitHub_13486.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
<OutputType>Exe</OutputType>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<PropertyGroup>
<DebugType></DebugType>
<Optimize>False</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

0 comments on commit d93735c

Please sign in to comment.