提交 dfdc94b6 编写于 作者: W Wonseok Chae

Setting next statement inside a scope with a lambda cause NRE

This happens since setting next statement skips the closure initialization, which marks as hidden sequence point.

In this PR, we emit a regular sequence point instead of a hidden sequence point to closure initialization whenever necessary, so IP move won't skip closure initialization.
上级 cc6fa894
......@@ -694,22 +694,49 @@ private BoundBlock RewriteBlock(BoundBlock node, ArrayBuilder<BoundExpression> p
var newStatements = ArrayBuilder<BoundStatement>.GetInstance();
if (prologue.Count > 0)
{
newStatements.Add(new BoundSequencePoint(null, null) { WasCompilerGenerated = true });
}
InsertAndFreePrologue(newStatements, prologue);
foreach (var statement in node.Statements)
{
var replacement = (BoundStatement)this.Visit(statement);
if (replacement != null)
{
if (newStatements.Count == 0 && prologue.Count > 0)
{
for (int i = 0; i < prologue.Count; i++)
{
BoundStatement prologueStatement = new BoundExpressionStatement(prologue[i].Syntax, prologue[i]);
// transfer the bound sequence point from the first rewritten statement to the first prologue expression statement:
if (i == 0)
{
BoundSequencePoint sequencePoint;
BoundSequencePointWithSpan sequencePointWithSpan;
if ((sequencePointWithSpan = replacement as BoundSequencePointWithSpan) != null)
{
prologueStatement = new BoundSequencePointWithSpan(sequencePointWithSpan.Syntax, prologueStatement, sequencePointWithSpan.Span);
replacement = sequencePointWithSpan.StatementOpt;
}
else if ((sequencePoint = replacement as BoundSequencePoint) != null)
{
prologueStatement = new BoundSequencePoint(sequencePoint.Syntax, prologueStatement);
replacement = sequencePoint.StatementOpt;
}
}
newStatements.Add(prologueStatement);
}
if (replacement == null)
{
continue;
}
}
newStatements.Add(replacement);
}
}
prologue.Free();
// TODO: we may not need to update if there was nothing to rewrite.
return node.Update(newLocals.ToImmutableAndFree(), newStatements.ToImmutableAndFree());
}
......
......@@ -624,7 +624,7 @@ static async Task M(int b)
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0x7"" hidden=""true"" document=""0"" />
<entry offset=""0xa"" hidden=""true"" document=""0"" />
<entry offset=""0xa"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x10"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x17"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x1e"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
......@@ -712,7 +712,7 @@ static async Task M(int b)
<customDebugInfo>
<forward declaringType=""C"" methodName=""F"" />
<hoistedLocalScopes>
<slot startOffset=""0x11"" endOffset=""0xe0"" />
<slot startOffset=""0x11"" endOffset=""0xdf"" />
</hoistedLocalScopes>
<encLocalSlotMap>
<slot kind=""27"" offset=""0"" />
......@@ -724,21 +724,20 @@ static async Task M(int b)
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0x7"" hidden=""true"" document=""0"" />
<entry offset=""0x11"" hidden=""true"" document=""0"" />
<entry offset=""0x1c"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x1d"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x29"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x35"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x41"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x58"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""31"" document=""0"" />
<entry offset=""0x86"" hidden=""true"" document=""0"" />
<entry offset=""0xe1"" hidden=""true"" document=""0"" />
<entry offset=""0xf9"" startLine=""19"" startColumn=""5"" endLine=""19"" endColumn=""6"" document=""0"" />
<entry offset=""0x101"" hidden=""true"" document=""0"" />
<entry offset=""0x11"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x1c"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x28"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x34"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x40"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x57"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""31"" document=""0"" />
<entry offset=""0x85"" hidden=""true"" document=""0"" />
<entry offset=""0xe0"" hidden=""true"" document=""0"" />
<entry offset=""0xf8"" startLine=""19"" startColumn=""5"" endLine=""19"" endColumn=""6"" document=""0"" />
<entry offset=""0x100"" hidden=""true"" document=""0"" />
</sequencePoints>
<asyncInfo>
<kickoffMethod declaringType=""C"" methodName=""M"" parameterNames=""b"" />
<await yield=""0x98"" resume=""0xb3"" declaringType=""C+&lt;M&gt;d__0"" methodName=""MoveNext"" />
<await yield=""0x97"" resume=""0xb2"" declaringType=""C+&lt;M&gt;d__0"" methodName=""MoveNext"" />
</asyncInfo>
</method>
</methods>
......@@ -815,7 +814,7 @@ static async Task M(int b)
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0x7"" hidden=""true"" document=""0"" />
<entry offset=""0xa"" hidden=""true"" document=""0"" />
<entry offset=""0xa"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x15"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x21"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x2d"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
......@@ -898,7 +897,7 @@ static async Task M(int b)
<customDebugInfo>
<forward declaringType=""C"" methodName=""F"" />
<hoistedLocalScopes>
<slot startOffset=""0x11"" endOffset=""0xcf"" />
<slot startOffset=""0xe"" endOffset=""0xcb"" />
</hoistedLocalScopes>
<encLocalSlotMap>
<slot kind=""27"" offset=""0"" />
......@@ -910,22 +909,21 @@ static async Task M(int b)
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0x7"" hidden=""true"" document=""0"" />
<entry offset=""0x11"" hidden=""true"" document=""0"" />
<entry offset=""0x1c"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x1d"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x29"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x35"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x41"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x58"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""29"" document=""0"" />
<entry offset=""0x64"" hidden=""true"" document=""0"" />
<entry offset=""0xbd"" startLine=""17"" startColumn=""9"" endLine=""17"" endColumn=""31"" document=""0"" />
<entry offset=""0xd0"" hidden=""true"" document=""0"" />
<entry offset=""0xe8"" startLine=""18"" startColumn=""5"" endLine=""18"" endColumn=""6"" document=""0"" />
<entry offset=""0xf0"" hidden=""true"" document=""0"" />
<entry offset=""0xe"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x19"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x25"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x31"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x3d"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x54"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""29"" document=""0"" />
<entry offset=""0x60"" hidden=""true"" document=""0"" />
<entry offset=""0xb9"" startLine=""17"" startColumn=""9"" endLine=""17"" endColumn=""31"" document=""0"" />
<entry offset=""0xcc"" hidden=""true"" document=""0"" />
<entry offset=""0xe4"" startLine=""18"" startColumn=""5"" endLine=""18"" endColumn=""6"" document=""0"" />
<entry offset=""0xec"" hidden=""true"" document=""0"" />
</sequencePoints>
<asyncInfo>
<kickoffMethod declaringType=""C"" methodName=""M"" parameterNames=""b"" />
<await yield=""0x76"" resume=""0x91"" declaringType=""C+&lt;M&gt;d__0"" methodName=""MoveNext"" />
<await yield=""0x72"" resume=""0x8d"" declaringType=""C+&lt;M&gt;d__0"" methodName=""MoveNext"" />
</asyncInfo>
</method>
</methods>
......
......@@ -1029,7 +1029,7 @@ static IEnumerable<int> M()
<customDebugInfo>
<forward declaringType=""C+&lt;&gt;c__DisplayClass0_0"" methodName=""&lt;M&gt;b__0"" />
<hoistedLocalScopes>
<slot startOffset=""0x32"" endOffset=""0xfb"" />
<slot startOffset=""0x32"" endOffset=""0xfa"" />
</hoistedLocalScopes>
<encLocalSlotMap>
<slot kind=""27"" offset=""0"" />
......@@ -1038,17 +1038,16 @@ static IEnumerable<int> M()
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0x32"" hidden=""true"" document=""0"" />
<entry offset=""0x3d"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x3e"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x4a"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x56"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x62"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x79"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""35"" document=""0"" />
<entry offset=""0xb0"" hidden=""true"" document=""0"" />
<entry offset=""0xb7"" startLine=""16"" startColumn=""9"" endLine=""16"" endColumn=""35"" document=""0"" />
<entry offset=""0xee"" hidden=""true"" document=""0"" />
<entry offset=""0xf5"" startLine=""17"" startColumn=""5"" endLine=""17"" endColumn=""6"" document=""0"" />
<entry offset=""0x32"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x3d"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x49"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x55"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x61"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x78"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""35"" document=""0"" />
<entry offset=""0xaf"" hidden=""true"" document=""0"" />
<entry offset=""0xb6"" startLine=""16"" startColumn=""9"" endLine=""16"" endColumn=""35"" document=""0"" />
<entry offset=""0xed"" hidden=""true"" document=""0"" />
<entry offset=""0xf4"" startLine=""17"" startColumn=""5"" endLine=""17"" endColumn=""6"" document=""0"" />
</sequencePoints>
</method>
</methods>
......@@ -1150,7 +1149,7 @@ .locals init (int V_0)
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0x17"" hidden=""true"" document=""0"" />
<entry offset=""0x17"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x1c"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x23"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x2a"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
......@@ -1222,7 +1221,7 @@ static IEnumerable<int> M()
v.VerifyIL("C.<M>d__0.System.Collections.IEnumerator.MoveNext", @"
{
// Code size 133 (0x85)
// Code size 132 (0x84)
.maxstack 2
.locals init (int V_0,
bool V_1)
......@@ -1237,7 +1236,7 @@ .maxstack 2
IL_000e: beq.s IL_0014
IL_0010: br.s IL_0016
IL_0012: br.s IL_001a
IL_0014: br.s IL_007a
IL_0014: br.s IL_0079
IL_0016: ldc.i4.0
IL_0017: stloc.1
IL_0018: ldloc.1
......@@ -1248,40 +1247,39 @@ .maxstack 2
IL_0021: ldarg.0
IL_0022: newobj ""C.<>c__DisplayClass0_0..ctor()""
IL_0027: stfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_002c: nop
IL_002d: ldarg.0
IL_002e: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_0033: ldc.i4.1
IL_0034: stfld ""byte C.<>c__DisplayClass0_0.x1""
IL_0039: ldarg.0
IL_003a: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_003f: ldc.i4.1
IL_0040: stfld ""byte C.<>c__DisplayClass0_0.x2""
IL_0045: ldarg.0
IL_0046: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_004b: ldc.i4.1
IL_004c: stfld ""byte C.<>c__DisplayClass0_0.x3""
IL_0051: ldarg.0
IL_0052: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_0057: ldftn ""void C.<>c__DisplayClass0_0.<M>b__0()""
IL_005d: newobj ""System.Action..ctor(object, System.IntPtr)""
IL_0062: callvirt ""void System.Action.Invoke()""
IL_0067: nop
IL_0068: ldarg.0
IL_0069: ldc.i4.1
IL_006a: stfld ""int C.<M>d__0.<>2__current""
IL_006f: ldarg.0
IL_0070: ldc.i4.1
IL_0071: stfld ""int C.<M>d__0.<>1__state""
IL_0076: ldc.i4.1
IL_0077: stloc.1
IL_0078: br.s IL_0018
IL_007a: ldarg.0
IL_007b: ldc.i4.m1
IL_007c: stfld ""int C.<M>d__0.<>1__state""
IL_0081: ldc.i4.0
IL_0082: stloc.1
IL_0083: br.s IL_0018
IL_002c: ldarg.0
IL_002d: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_0032: ldc.i4.1
IL_0033: stfld ""byte C.<>c__DisplayClass0_0.x1""
IL_0038: ldarg.0
IL_0039: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_003e: ldc.i4.1
IL_003f: stfld ""byte C.<>c__DisplayClass0_0.x2""
IL_0044: ldarg.0
IL_0045: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_004a: ldc.i4.1
IL_004b: stfld ""byte C.<>c__DisplayClass0_0.x3""
IL_0050: ldarg.0
IL_0051: ldfld ""C.<>c__DisplayClass0_0 C.<M>d__0.<>8__1""
IL_0056: ldftn ""void C.<>c__DisplayClass0_0.<M>b__0()""
IL_005c: newobj ""System.Action..ctor(object, System.IntPtr)""
IL_0061: callvirt ""void System.Action.Invoke()""
IL_0066: nop
IL_0067: ldarg.0
IL_0068: ldc.i4.1
IL_0069: stfld ""int C.<M>d__0.<>2__current""
IL_006e: ldarg.0
IL_006f: ldc.i4.1
IL_0070: stfld ""int C.<M>d__0.<>1__state""
IL_0075: ldc.i4.1
IL_0076: stloc.1
IL_0077: br.s IL_0018
IL_0079: ldarg.0
IL_007a: ldc.i4.m1
IL_007b: stfld ""int C.<M>d__0.<>1__state""
IL_0080: ldc.i4.0
IL_0081: stloc.1
IL_0082: br.s IL_0018
}
");
......@@ -1292,7 +1290,7 @@ .maxstack 2
<customDebugInfo>
<forward declaringType=""C"" methodName=""F"" />
<hoistedLocalScopes>
<slot startOffset=""0x21"" endOffset=""0x84"" />
<slot startOffset=""0x21"" endOffset=""0x83"" />
</hoistedLocalScopes>
<encLocalSlotMap>
<slot kind=""27"" offset=""0"" />
......@@ -1301,15 +1299,14 @@ .maxstack 2
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0x21"" hidden=""true"" document=""0"" />
<entry offset=""0x2c"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x2d"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x39"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x45"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x51"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x68"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""24"" document=""0"" />
<entry offset=""0x7a"" hidden=""true"" document=""0"" />
<entry offset=""0x81"" startLine=""19"" startColumn=""5"" endLine=""19"" endColumn=""6"" document=""0"" />
<entry offset=""0x21"" startLine=""8"" startColumn=""5"" endLine=""8"" endColumn=""6"" document=""0"" />
<entry offset=""0x2c"" startLine=""9"" startColumn=""9"" endLine=""9"" endColumn=""21"" document=""0"" />
<entry offset=""0x38"" startLine=""10"" startColumn=""9"" endLine=""10"" endColumn=""21"" document=""0"" />
<entry offset=""0x44"" startLine=""11"" startColumn=""9"" endLine=""11"" endColumn=""21"" document=""0"" />
<entry offset=""0x50"" startLine=""13"" startColumn=""9"" endLine=""13"" endColumn=""47"" document=""0"" />
<entry offset=""0x67"" startLine=""15"" startColumn=""9"" endLine=""15"" endColumn=""24"" document=""0"" />
<entry offset=""0x79"" hidden=""true"" document=""0"" />
<entry offset=""0x80"" startLine=""19"" startColumn=""5"" endLine=""19"" endColumn=""6"" document=""0"" />
</sequencePoints>
</method>
</methods>
......
......@@ -323,8 +323,7 @@ class C
</encLocalSlotMap>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" hidden=""true"" document=""0"" />
<entry offset=""0xd"" startLine=""7"" startColumn=""61"" endLine=""7"" endColumn=""70"" document=""0"" />
<entry offset=""0x0"" startLine=""7"" startColumn=""61"" endLine=""7"" endColumn=""70"" document=""0"" />
</sequencePoints>
<scope startOffset=""0x0"" endOffset=""0x1e"">
<local name=""CS$&lt;&gt;8__locals0"" il_index=""0"" il_start=""0x0"" il_end=""0x1e"" attributes=""0"" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册