Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
93ae706d
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,发现更多精彩内容 >>
提交
93ae706d
编写于
9月 27, 2017
作者:
A
Andy Gocke
提交者:
GitHub
9月 27, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make readonlyness of ref-ternary the AND of operands (#22384)
Fixes #22378
上级
b27dd507
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
184 addition
and
4 deletion
+184
-4
src/Compilers/CSharp/Portable/CodeGen/EmitAddress.cs
src/Compilers/CSharp/Portable/CodeGen/EmitAddress.cs
+1
-1
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenConditionalOperatorTests.cs
...harp/Test/Emit/CodeGen/CodeGenConditionalOperatorTests.cs
+180
-0
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefConditionalOperatorTests.cs
...p/Test/Emit/CodeGen/CodeGenRefConditionalOperatorTests.cs
+3
-3
未找到文件。
src/Compilers/CSharp/Portable/CodeGen/EmitAddress.cs
浏览文件 @
93ae706d
...
...
@@ -415,7 +415,7 @@ private bool HasHome(BoundExpression expression, bool needWriteable)
// branch that has no home will need a temporary
// if both have no home, just say whole expression has no home
// so we could just use one temp for the whole thing
return
HasHome
(
ternary
.
Consequence
,
needWriteable
)
||
HasHome
(
ternary
.
Alternative
,
needWriteable
);
return
HasHome
(
ternary
.
Consequence
,
needWriteable
)
&&
HasHome
(
ternary
.
Alternative
,
needWriteable
);
default
:
return
false
;
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenConditionalOperatorTests.cs
浏览文件 @
93ae706d
...
...
@@ -2471,6 +2471,186 @@ static void Main()
CompileAndVerify
(
source
,
expectedOutput
:
expectedOutput
);
}
[
Fact
]
public
void
RefReadonlyConditional
()
{
var
comp
=
CompileAndVerify
(
@"
using System;
struct S
{
public int X;
public S(int x) => X = x;
public void Mutate() => X++;
}
class C
{
static void Main()
{
S local1 = new S(0);
S local2 = new S(0);
Console.WriteLine(local1.X);
Console.WriteLine(local2.X);
bool condition = false;
(condition ? ref local1 : ref local2).Mutate();
Console.WriteLine(local1.X);
Console.WriteLine(local2.X);
(condition ? ref local1 : ref local2).X = 0;
Console.WriteLine(local1.X);
Console.WriteLine(local2.X);
ref readonly S ro1 = ref local1;
ref readonly S ro2 = ref local2;
(condition ? ref local1 : ref ro2).Mutate();
Console.WriteLine(local1.X);
Console.WriteLine(local2.X);
(condition ? ref ro1 : ref local2).Mutate();
Console.WriteLine(local1.X);
Console.WriteLine(local2.X);
(!condition ? ref local1 : ref ro2).Mutate();
Console.WriteLine(local1.X);
Console.WriteLine(local2.X);
(!condition ? ref ro1 : ref local2).Mutate();
Console.WriteLine(local1.X);
Console.WriteLine(local2.X);
}
}"
,
expectedOutput
:
@"0
0
0
1
0
0
0
0
0
0
0
0
0
0"
);
comp
.
VerifyIL
(
"C.Main"
,
@"
{
// Code size 290 (0x122)
.maxstack 3
.locals init (S V_0, //local1
S V_1, //local2
S& V_2, //ro1
S& V_3, //ro2
S V_4)
IL_0000: ldloca.s V_0
IL_0002: ldc.i4.0
IL_0003: call ""S..ctor(int)""
IL_0008: ldloca.s V_1
IL_000a: ldc.i4.0
IL_000b: call ""S..ctor(int)""
IL_0010: ldloc.0
IL_0011: ldfld ""int S.X""
IL_0016: call ""void System.Console.WriteLine(int)""
IL_001b: ldloc.1
IL_001c: ldfld ""int S.X""
IL_0021: call ""void System.Console.WriteLine(int)""
IL_0026: ldc.i4.0
IL_0027: dup
IL_0028: brtrue.s IL_002e
IL_002a: ldloca.s V_1
IL_002c: br.s IL_0030
IL_002e: ldloca.s V_0
IL_0030: call ""void S.Mutate()""
IL_0035: ldloc.0
IL_0036: ldfld ""int S.X""
IL_003b: call ""void System.Console.WriteLine(int)""
IL_0040: ldloc.1
IL_0041: ldfld ""int S.X""
IL_0046: call ""void System.Console.WriteLine(int)""
IL_004b: dup
IL_004c: brtrue.s IL_0052
IL_004e: ldloca.s V_1
IL_0050: br.s IL_0054
IL_0052: ldloca.s V_0
IL_0054: ldc.i4.0
IL_0055: stfld ""int S.X""
IL_005a: ldloc.0
IL_005b: ldfld ""int S.X""
IL_0060: call ""void System.Console.WriteLine(int)""
IL_0065: ldloc.1
IL_0066: ldfld ""int S.X""
IL_006b: call ""void System.Console.WriteLine(int)""
IL_0070: ldloca.s V_0
IL_0072: stloc.2
IL_0073: ldloca.s V_1
IL_0075: stloc.3
IL_0076: dup
IL_0077: brtrue.s IL_0081
IL_0079: ldloc.3
IL_007a: ldobj ""S""
IL_007f: br.s IL_0082
IL_0081: ldloc.0
IL_0082: stloc.s V_4
IL_0084: ldloca.s V_4
IL_0086: call ""void S.Mutate()""
IL_008b: ldloc.0
IL_008c: ldfld ""int S.X""
IL_0091: call ""void System.Console.WriteLine(int)""
IL_0096: ldloc.1
IL_0097: ldfld ""int S.X""
IL_009c: call ""void System.Console.WriteLine(int)""
IL_00a1: dup
IL_00a2: brtrue.s IL_00a7
IL_00a4: ldloc.1
IL_00a5: br.s IL_00ad
IL_00a7: ldloc.2
IL_00a8: ldobj ""S""
IL_00ad: stloc.s V_4
IL_00af: ldloca.s V_4
IL_00b1: call ""void S.Mutate()""
IL_00b6: ldloc.0
IL_00b7: ldfld ""int S.X""
IL_00bc: call ""void System.Console.WriteLine(int)""
IL_00c1: ldloc.1
IL_00c2: ldfld ""int S.X""
IL_00c7: call ""void System.Console.WriteLine(int)""
IL_00cc: dup
IL_00cd: brfalse.s IL_00d7
IL_00cf: ldloc.3
IL_00d0: ldobj ""S""
IL_00d5: br.s IL_00d8
IL_00d7: ldloc.0
IL_00d8: stloc.s V_4
IL_00da: ldloca.s V_4
IL_00dc: call ""void S.Mutate()""
IL_00e1: ldloc.0
IL_00e2: ldfld ""int S.X""
IL_00e7: call ""void System.Console.WriteLine(int)""
IL_00ec: ldloc.1
IL_00ed: ldfld ""int S.X""
IL_00f2: call ""void System.Console.WriteLine(int)""
IL_00f7: brfalse.s IL_00fc
IL_00f9: ldloc.1
IL_00fa: br.s IL_0102
IL_00fc: ldloc.2
IL_00fd: ldobj ""S""
IL_0102: stloc.s V_4
IL_0104: ldloca.s V_4
IL_0106: call ""void S.Mutate()""
IL_010b: ldloc.0
IL_010c: ldfld ""int S.X""
IL_0111: call ""void System.Console.WriteLine(int)""
IL_0116: ldloc.1
IL_0117: ldfld ""int S.X""
IL_011c: call ""void System.Console.WriteLine(int)""
IL_0121: ret
}"
);
}
[
Fact
]
public
void
RefConditionalOperatorInValConditional
()
{
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefConditionalOperatorTests.cs
浏览文件 @
93ae706d
...
...
@@ -1113,7 +1113,7 @@ public override string ToString()
}
"
;
var
comp
=
CompileAndVerify
(
source
,
additionalRefs
:
new
[]
{
SystemRuntimeFacadeRef
,
ValueTupleRef
},
expectedOutput
:
"0
42
"
,
verify
:
false
);
var
comp
=
CompileAndVerify
(
source
,
additionalRefs
:
new
[]
{
SystemRuntimeFacadeRef
,
ValueTupleRef
},
expectedOutput
:
"0
0
"
,
verify
:
false
);
comp
.
VerifyDiagnostics
();
comp
.
VerifyIL
(
"Program.Test"
,
@"
...
...
@@ -1124,8 +1124,8 @@ .locals init (S1 V_0)
IL_0000: ldarg.0
IL_0001: brtrue.s IL_000b
IL_0003: ldarg.1
IL_0004: ldfld
a
""S1 C1.field1""
IL_0009: br.s IL_001
4
IL_0004: ldfld
""S1 C1.field1""
IL_0009: br.s IL_001
1
IL_000b: ldarg.1
IL_000c: ldfld ""S1 C1.field""
IL_0011: stloc.0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录