Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
ec603dc6
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ec603dc6
编写于
12月 18, 2019
作者:
R
Rikki Gibson
提交者:
GitHub
12月 18, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use a temp for pattern input when a local or parameter is ref/in/out (#40479)
上级
d0dfb574
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
191 addition
and
1 deletion
+191
-1
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Patterns.cs
...Portable/Lowering/LocalRewriter/LocalRewriter_Patterns.cs
+2
-1
src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs
src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs
+189
-0
未找到文件。
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Patterns.cs
浏览文件 @
ec603dc6
...
@@ -397,7 +397,8 @@ private BoundExpression MakeEqual(BoundExpression loweredLiteral, BoundExpressio
...
@@ -397,7 +397,8 @@ private BoundExpression MakeEqual(BoundExpression loweredLiteral, BoundExpressio
out
BoundExpression
savedInputExpression
)
out
BoundExpression
savedInputExpression
)
{
{
var
inputDagTemp
=
BoundDagTemp
.
ForOriginalInput
(
loweredInput
);
var
inputDagTemp
=
BoundDagTemp
.
ForOriginalInput
(
loweredInput
);
if
(
loweredInput
.
Kind
==
BoundKind
.
Local
||
loweredInput
.
Kind
==
BoundKind
.
Parameter
)
if
((
loweredInput
.
Kind
==
BoundKind
.
Local
||
loweredInput
.
Kind
==
BoundKind
.
Parameter
)
&&
loweredInput
.
GetRefKind
()
==
RefKind
.
None
)
{
{
// If we're switching on a local variable and there is no when clause (checked by the caller),
// If we're switching on a local variable and there is no when clause (checked by the caller),
// we assume the value of the local variable does not change during the execution of the
// we assume the value of the local variable does not change during the execution of the
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs
浏览文件 @
ec603dc6
...
@@ -773,6 +773,195 @@ .maxstack 2
...
@@ -773,6 +773,195 @@ .maxstack 2
}"
);
}"
);
}
}
[
Fact
,
WorkItem
(
40403
,
"https://github.com/dotnet/roslyn/issues/40403"
)]
public
void
RefParameter_StoreToTemp
()
{
var
source
=
@"public class C
{
static bool M1(ref object x)
{
return x is 42;
}
}"
;
var
compilation
=
CreateCompilation
(
source
,
options
:
TestOptions
.
ReleaseDll
);
compilation
.
VerifyDiagnostics
();
var
compVerifier
=
CompileAndVerify
(
compilation
);
compVerifier
.
VerifyIL
(
"C.M1"
,
@"{
// Code size 24 (0x18)
.maxstack 2
.locals init (object V_0)
IL_0000: ldarg.0
IL_0001: ldind.ref
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: isinst ""int""
IL_0009: brfalse.s IL_0016
IL_000b: ldloc.0
IL_000c: unbox.any ""int""
IL_0011: ldc.i4.s 42
IL_0013: ceq
IL_0015: ret
IL_0016: ldc.i4.0
IL_0017: ret
}"
);
}
[
Fact
,
WorkItem
(
40403
,
"https://github.com/dotnet/roslyn/issues/40403"
)]
public
void
RefLocal_StoreToTemp
()
{
var
source
=
@"public class C
{
static bool M1(bool b, ref object x, ref object y)
{
ref object z = ref b ? ref x : ref y;
return z is 42;
}
}"
;
var
compilation
=
CreateCompilation
(
source
,
options
:
TestOptions
.
ReleaseDll
);
compilation
.
VerifyDiagnostics
();
var
compVerifier
=
CompileAndVerify
(
compilation
);
compVerifier
.
VerifyIL
(
"C.M1"
,
@"{
// Code size 30 (0x1e)
.maxstack 2
.locals init (object V_0)
IL_0000: ldarg.0
IL_0001: brtrue.s IL_0006
IL_0003: ldarg.2
IL_0004: br.s IL_0007
IL_0006: ldarg.1
IL_0007: ldind.ref
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: isinst ""int""
IL_000f: brfalse.s IL_001c
IL_0011: ldloc.0
IL_0012: unbox.any ""int""
IL_0017: ldc.i4.s 42
IL_0019: ceq
IL_001b: ret
IL_001c: ldc.i4.0
IL_001d: ret
}"
);
}
[
Fact
,
WorkItem
(
40403
,
"https://github.com/dotnet/roslyn/issues/40403"
)]
public
void
InParameter_StoreToTemp
()
{
var
source
=
@"public class C
{
static bool M1(in object x)
{
return x is 42;
}
}"
;
var
compilation
=
CreateCompilation
(
source
,
options
:
TestOptions
.
ReleaseDll
);
compilation
.
VerifyDiagnostics
();
var
compVerifier
=
CompileAndVerify
(
compilation
);
compVerifier
.
VerifyIL
(
"C.M1"
,
@"{
// Code size 24 (0x18)
.maxstack 2
.locals init (object V_0)
IL_0000: ldarg.0
IL_0001: ldind.ref
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: isinst ""int""
IL_0009: brfalse.s IL_0016
IL_000b: ldloc.0
IL_000c: unbox.any ""int""
IL_0011: ldc.i4.s 42
IL_0013: ceq
IL_0015: ret
IL_0016: ldc.i4.0
IL_0017: ret
}"
);
}
[
Fact
,
WorkItem
(
40403
,
"https://github.com/dotnet/roslyn/issues/40403"
)]
public
void
RefReadonlyLocal_StoreToTemp
()
{
var
source
=
@"public class C
{
static bool M1(bool b, in object x, in object y)
{
ref readonly object z = ref b ? ref x : ref y;
return z is 42;
}
}"
;
var
compilation
=
CreateCompilation
(
source
,
options
:
TestOptions
.
ReleaseDll
);
compilation
.
VerifyDiagnostics
();
var
compVerifier
=
CompileAndVerify
(
compilation
);
compVerifier
.
VerifyIL
(
"C.M1"
,
@"{
// Code size 30 (0x1e)
.maxstack 2
.locals init (object V_0)
IL_0000: ldarg.0
IL_0001: brtrue.s IL_0006
IL_0003: ldarg.2
IL_0004: br.s IL_0007
IL_0006: ldarg.1
IL_0007: ldind.ref
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: isinst ""int""
IL_000f: brfalse.s IL_001c
IL_0011: ldloc.0
IL_0012: unbox.any ""int""
IL_0017: ldc.i4.s 42
IL_0019: ceq
IL_001b: ret
IL_001c: ldc.i4.0
IL_001d: ret
}"
);
}
[
Fact
,
WorkItem
(
40403
,
"https://github.com/dotnet/roslyn/issues/40403"
)]
public
void
OutParameter_StoreToTemp
()
{
var
source
=
@"public class C
{
static bool M1(out object x)
{
x = null;
return x is 42;
}
}"
;
var
compilation
=
CreateCompilation
(
source
,
options
:
TestOptions
.
ReleaseDll
);
compilation
.
VerifyDiagnostics
();
var
compVerifier
=
CompileAndVerify
(
compilation
);
compVerifier
.
VerifyIL
(
"C.M1"
,
@"{
// Code size 27 (0x1b)
.maxstack 2
.locals init (object V_0)
IL_0000: ldarg.0
IL_0001: ldnull
IL_0002: stind.ref
IL_0003: ldarg.0
IL_0004: ldind.ref
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: isinst ""int""
IL_000c: brfalse.s IL_0019
IL_000e: ldloc.0
IL_000f: unbox.any ""int""
IL_0014: ldc.i4.s 42
IL_0016: ceq
IL_0018: ret
IL_0019: ldc.i4.0
IL_001a: ret
}"
);
}
[
Fact
,
WorkItem
(
22654
,
"https://github.com/dotnet/roslyn/issues/22654"
)]
[
Fact
,
WorkItem
(
22654
,
"https://github.com/dotnet/roslyn/issues/22654"
)]
public
void
NoRedundantTypeCheck
()
public
void
NoRedundantTypeCheck
()
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录