Browse Source

Merge pull request #1920 from icsharpcode/fix-1919

Fix #1919: Use unmapped IL offsets at the start of a catch-block for the 'exception specifier' sequence point.
pull/2016/head
Daniel Grunwald 5 years ago committed by GitHub
parent
commit
c71802fd7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  2. 45
      ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs
  3. 1
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  4. 166
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs
  5. 25
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs
  6. 13
      ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs
  7. 14
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

4
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -1812,11 +1812,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
Space(); Space();
WriteKeyword(CatchClause.WhenKeywordRole); WriteKeyword(CatchClause.WhenKeywordRole);
Space(policy.SpaceBeforeIfParentheses); Space(policy.SpaceBeforeIfParentheses);
LPar(); WriteToken(CatchClause.CondLPar);
Space(policy.SpacesWithinIfParentheses); Space(policy.SpacesWithinIfParentheses);
catchClause.Condition.AcceptVisitor(this); catchClause.Condition.AcceptVisitor(this);
Space(policy.SpacesWithinIfParentheses); Space(policy.SpacesWithinIfParentheses);
RPar(); WriteToken(CatchClause.CondRPar);
} }
WriteBlock(catchClause.Body, policy.StatementBraceStyle); WriteBlock(catchClause.Body, policy.StatementBraceStyle);
EndNode(catchClause); EndNode(catchClause);

45
ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs

@ -113,7 +113,13 @@ namespace ICSharpCode.Decompiler.CSharp
ILInstruction blockContainer = blockStatement.Annotations.OfType<ILInstruction>().FirstOrDefault(); ILInstruction blockContainer = blockStatement.Annotations.OfType<ILInstruction>().FirstOrDefault();
if (blockContainer != null) { if (blockContainer != null) {
StartSequencePoint(blockStatement.LBraceToken); StartSequencePoint(blockStatement.LBraceToken);
int intervalStart = blockContainer.ILRanges.First().Start; int intervalStart;
if (blockContainer.Parent is TryCatchHandler handler && !handler.ExceptionSpecifierILRange.IsEmpty) {
// if this block container is part of a TryCatchHandler, do not steal the exception-specifier IL range
intervalStart = handler.ExceptionSpecifierILRange.End;
} else {
intervalStart = blockContainer.StartILOffset;
}
// The end will be set to the first sequence point candidate location before the first statement of the function when the seqeunce point is adjusted // The end will be set to the first sequence point candidate location before the first statement of the function when the seqeunce point is adjusted
int intervalEnd = intervalStart + 1; int intervalEnd = intervalStart + 1;
@ -256,12 +262,15 @@ namespace ICSharpCode.Decompiler.CSharp
foreachStatement.InExpression.AcceptVisitor(this); foreachStatement.InExpression.AcceptVisitor(this);
AddToSequencePoint(foreachInfo.GetEnumeratorCall); AddToSequencePoint(foreachInfo.GetEnumeratorCall);
EndSequencePoint(foreachStatement.InExpression.StartLocation, foreachStatement.InExpression.EndLocation); EndSequencePoint(foreachStatement.InExpression.StartLocation, foreachStatement.InExpression.EndLocation);
StartSequencePoint(foreachStatement); StartSequencePoint(foreachStatement);
AddToSequencePoint(foreachInfo.MoveNextCall); AddToSequencePoint(foreachInfo.MoveNextCall);
EndSequencePoint(foreachStatement.InToken.StartLocation, foreachStatement.InToken.EndLocation); EndSequencePoint(foreachStatement.InToken.StartLocation, foreachStatement.InToken.EndLocation);
StartSequencePoint(foreachStatement); StartSequencePoint(foreachStatement);
AddToSequencePoint(foreachInfo.GetCurrentCall); AddToSequencePoint(foreachInfo.GetCurrentCall);
EndSequencePoint(foreachStatement.VariableType.StartLocation, foreachStatement.VariableNameToken.EndLocation); EndSequencePoint(foreachStatement.VariableType.StartLocation, foreachStatement.VariableNameToken.EndLocation);
VisitAsSequencePoint(foreachStatement.EmbeddedStatement); VisitAsSequencePoint(foreachStatement.EmbeddedStatement);
} }
@ -310,6 +319,33 @@ namespace ICSharpCode.Decompiler.CSharp
VisitAsSequencePoint(fixedStatement.EmbeddedStatement); VisitAsSequencePoint(fixedStatement.EmbeddedStatement);
} }
public override void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
{
VisitAsSequencePoint(tryCatchStatement.TryBlock);
foreach (var c in tryCatchStatement.CatchClauses) {
VisitAsSequencePoint(c);
}
VisitAsSequencePoint(tryCatchStatement.FinallyBlock);
}
public override void VisitCatchClause(CatchClause catchClause)
{
if (catchClause.Condition.IsNull) {
var tryCatchHandler = catchClause.Annotation<TryCatchHandler>();
if (!tryCatchHandler.ExceptionSpecifierILRange.IsEmpty) {
StartSequencePoint(catchClause.CatchToken);
var function = tryCatchHandler.Ancestors.OfType<ILFunction>().FirstOrDefault();
AddToSequencePointRaw(function, new[] { tryCatchHandler.ExceptionSpecifierILRange });
EndSequencePoint(catchClause.CatchToken.StartLocation, catchClause.RParToken.IsNull ? catchClause.CatchToken.EndLocation : catchClause.RParToken.EndLocation);
}
} else {
StartSequencePoint(catchClause.WhenToken);
AddToSequencePoint(catchClause.Condition);
EndSequencePoint(catchClause.WhenToken.StartLocation, catchClause.CondRParToken.EndLocation);
}
VisitAsSequencePoint(catchClause.Body);
}
/// <summary> /// <summary>
/// Start a new C# statement = new sequence point. /// Start a new C# statement = new sequence point.
/// </summary> /// </summary>
@ -339,6 +375,13 @@ namespace ICSharpCode.Decompiler.CSharp
current = outerStates.Pop(); current = outerStates.Pop();
} }
void AddToSequencePointRaw(ILFunction function, IEnumerable<Interval> ranges)
{
current.Intervals.AddRange(ranges);
Debug.Assert(current.Function == null || current.Function == function);
current.Function = function;
}
/// <summary> /// <summary>
/// Add the ILAst instruction associated with the AstNode to the sequence point. /// Add the ILAst instruction associated with the AstNode to the sequence point.
/// Also add all its ILAst sub-instructions (unless they were already added to another sequence point). /// Also add all its ILAst sub-instructions (unless they were already added to another sequence point).

1
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -363,6 +363,7 @@ namespace ICSharpCode.Decompiler.CSharp
tryCatch.TryBlock = ConvertAsBlock(inst.TryBlock); tryCatch.TryBlock = ConvertAsBlock(inst.TryBlock);
foreach (var handler in inst.Handlers) { foreach (var handler in inst.Handlers) {
var catchClause = new CatchClause(); var catchClause = new CatchClause();
catchClause.AddAnnotation(handler);
var v = handler.Variable; var v = handler.Variable;
if (v != null) { if (v != null) {
catchClause.AddAnnotation(new ILVariableResolveResult(v, v.Type)); catchClause.AddAnnotation(new ILVariableResolveResult(v, v.Type));

166
ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs

@ -32,68 +32,70 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public class TryCatchStatement : Statement public class TryCatchStatement : Statement
{ {
public static readonly TokenRole TryKeywordRole = new TokenRole ("try"); public static readonly TokenRole TryKeywordRole = new TokenRole("try");
public static readonly Role<BlockStatement> TryBlockRole = new Role<BlockStatement>("TryBlock", BlockStatement.Null); public static readonly Role<BlockStatement> TryBlockRole = new Role<BlockStatement>("TryBlock", BlockStatement.Null);
public static readonly Role<CatchClause> CatchClauseRole = new Role<CatchClause>("CatchClause", CatchClause.Null); public static readonly Role<CatchClause> CatchClauseRole = new Role<CatchClause>("CatchClause", CatchClause.Null);
public static readonly TokenRole FinallyKeywordRole = new TokenRole ("finally"); public static readonly TokenRole FinallyKeywordRole = new TokenRole("finally");
public static readonly Role<BlockStatement> FinallyBlockRole = new Role<BlockStatement>("FinallyBlock", BlockStatement.Null); public static readonly Role<BlockStatement> FinallyBlockRole = new Role<BlockStatement>("FinallyBlock", BlockStatement.Null);
public CSharpTokenNode TryToken { public CSharpTokenNode TryToken {
get { return GetChildByRole (TryKeywordRole); } get { return GetChildByRole(TryKeywordRole); }
} }
public BlockStatement TryBlock { public BlockStatement TryBlock {
get { return GetChildByRole (TryBlockRole); } get { return GetChildByRole(TryBlockRole); }
set { SetChildByRole (TryBlockRole, value); } set { SetChildByRole(TryBlockRole, value); }
} }
public AstNodeCollection<CatchClause> CatchClauses { public AstNodeCollection<CatchClause> CatchClauses {
get { return GetChildrenByRole (CatchClauseRole); } get { return GetChildrenByRole(CatchClauseRole); }
} }
public CSharpTokenNode FinallyToken { public CSharpTokenNode FinallyToken {
get { return GetChildByRole (FinallyKeywordRole); } get { return GetChildByRole(FinallyKeywordRole); }
} }
public BlockStatement FinallyBlock { public BlockStatement FinallyBlock {
get { return GetChildByRole (FinallyBlockRole); } get { return GetChildByRole(FinallyBlockRole); }
set { SetChildByRole (FinallyBlockRole, value); } set { SetChildByRole(FinallyBlockRole, value); }
} }
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor(IAstVisitor visitor)
{ {
visitor.VisitTryCatchStatement (this); visitor.VisitTryCatchStatement(this);
} }
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{ {
return visitor.VisitTryCatchStatement (this); return visitor.VisitTryCatchStatement(this);
} }
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitTryCatchStatement (this, data); return visitor.VisitTryCatchStatement(this, data);
} }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
TryCatchStatement o = other as TryCatchStatement; TryCatchStatement o = other as TryCatchStatement;
return o != null && this.TryBlock.DoMatch(o.TryBlock, match) && this.CatchClauses.DoMatch(o.CatchClauses, match) && this.FinallyBlock.DoMatch(o.FinallyBlock, match); return o != null && this.TryBlock.DoMatch(o.TryBlock, match) && this.CatchClauses.DoMatch(o.CatchClauses, match) && this.FinallyBlock.DoMatch(o.FinallyBlock, match);
} }
} }
/// <summary> /// <summary>
/// catch (Type VariableName) { Body } /// catch (Type VariableName) { Body }
/// </summary> /// </summary>
public class CatchClause : AstNode public class CatchClause : AstNode
{ {
public static readonly TokenRole CatchKeywordRole = new TokenRole ("catch"); public static readonly TokenRole CatchKeywordRole = new TokenRole("catch");
public static readonly TokenRole WhenKeywordRole = new TokenRole ("when"); public static readonly TokenRole WhenKeywordRole = new TokenRole("when");
public static readonly Role<Expression> ConditionRole = Roles.Condition; public static readonly Role<Expression> ConditionRole = Roles.Condition;
public static readonly TokenRole CondLPar = new TokenRole("(");
public static readonly TokenRole CondRPar = new TokenRole(")");
#region Null #region Null
public new static readonly CatchClause Null = new NullCatchClause (); public new static readonly CatchClause Null = new NullCatchClause();
sealed class NullCatchClause : CatchClause sealed class NullCatchClause : CatchClause
{ {
public override bool IsNull { public override bool IsNull {
@ -101,22 +103,22 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return true; return true;
} }
} }
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor(IAstVisitor visitor)
{ {
visitor.VisitNullNode(this); visitor.VisitNullNode(this);
} }
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{ {
return visitor.VisitNullNode(this); return visitor.VisitNullNode(this);
} }
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitNullNode(this, data); return visitor.VisitNullNode(this, data);
} }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
return other == null || other.IsNull; return other == null || other.IsNull;
@ -129,26 +131,26 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{ {
return pattern != null ? new PatternPlaceholder(pattern) : null; return pattern != null ? new PatternPlaceholder(pattern) : null;
} }
sealed class PatternPlaceholder : CatchClause, PatternMatching.INode sealed class PatternPlaceholder : CatchClause, PatternMatching.INode
{ {
readonly PatternMatching.Pattern child; readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child) public PatternPlaceholder(PatternMatching.Pattern child)
{ {
this.child = child; this.child = child;
} }
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.Pattern; } get { return NodeType.Pattern; }
} }
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor(IAstVisitor visitor)
{ {
visitor.VisitPatternPlaceholder(this, child); visitor.VisitPatternPlaceholder(this, child);
} }
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{ {
return visitor.VisitPatternPlaceholder(this, child); return visitor.VisitPatternPlaceholder(this, child);
} }
@ -157,90 +159,98 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{ {
return visitor.VisitPatternPlaceholder(this, child, data); return visitor.VisitPatternPlaceholder(this, child, data);
} }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
return child.DoMatch(other, match); return child.DoMatch(other, match);
} }
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{ {
return child.DoMatchCollection(role, pos, match, backtrackingInfo); return child.DoMatchCollection(role, pos, match, backtrackingInfo);
} }
} }
#endregion #endregion
public override NodeType NodeType { public override NodeType NodeType {
get { get {
return NodeType.Unknown; return NodeType.Unknown;
} }
} }
public CSharpTokenNode CatchToken { public CSharpTokenNode CatchToken {
get { return GetChildByRole (CatchKeywordRole); } get { return GetChildByRole(CatchKeywordRole); }
} }
public CSharpTokenNode LParToken { public CSharpTokenNode LParToken {
get { return GetChildByRole (Roles.LPar); } get { return GetChildByRole(Roles.LPar); }
} }
public AstType Type { public AstType Type {
get { return GetChildByRole (Roles.Type); } get { return GetChildByRole(Roles.Type); }
set { SetChildByRole (Roles.Type, value); } set { SetChildByRole(Roles.Type, value); }
} }
public string VariableName { public string VariableName {
get { return GetChildByRole (Roles.Identifier).Name; } get { return GetChildByRole(Roles.Identifier).Name; }
set { set {
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
SetChildByRole (Roles.Identifier, null); SetChildByRole(Roles.Identifier, null);
else else
SetChildByRole (Roles.Identifier, Identifier.Create (value)); SetChildByRole(Roles.Identifier, Identifier.Create(value));
} }
} }
public Identifier VariableNameToken { public Identifier VariableNameToken {
get { get {
return GetChildByRole (Roles.Identifier); return GetChildByRole(Roles.Identifier);
} }
set { set {
SetChildByRole(Roles.Identifier, value); SetChildByRole(Roles.Identifier, value);
} }
} }
public CSharpTokenNode RParToken { public CSharpTokenNode RParToken {
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole(Roles.RPar); }
} }
public CSharpTokenNode WhenToken { public CSharpTokenNode WhenToken {
get { return GetChildByRole (WhenKeywordRole); } get { return GetChildByRole(WhenKeywordRole); }
} }
public CSharpTokenNode CondLParToken {
get { return GetChildByRole(CondLPar); }
}
public Expression Condition { public Expression Condition {
get { return GetChildByRole(ConditionRole); } get { return GetChildByRole(ConditionRole); }
set { SetChildByRole(ConditionRole, value); } set { SetChildByRole(ConditionRole, value); }
} }
public CSharpTokenNode CondRParToken {
get { return GetChildByRole(CondRPar); }
}
public BlockStatement Body { public BlockStatement Body {
get { return GetChildByRole (Roles.Body); } get { return GetChildByRole(Roles.Body); }
set { SetChildByRole (Roles.Body, value); } set { SetChildByRole(Roles.Body, value); }
} }
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor(IAstVisitor visitor)
{ {
visitor.VisitCatchClause (this); visitor.VisitCatchClause(this);
} }
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{ {
return visitor.VisitCatchClause (this); return visitor.VisitCatchClause(this);
} }
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCatchClause (this, data); return visitor.VisitCatchClause(this, data);
} }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
CatchClause o = other as CatchClause; CatchClause o = other as CatchClause;

25
ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

@ -214,24 +214,29 @@ namespace ICSharpCode.Decompiler.IL
public void AddILRange(Interval newRange) public void AddILRange(Interval newRange)
{ {
if (this.ILRange.IsEmpty) { this.ILRange = CombineILRange(this.ILRange, newRange);
this.ILRange = newRange; }
return;
protected static Interval CombineILRange(Interval oldRange, Interval newRange)
{
if (oldRange.IsEmpty) {
return newRange;
} }
if (newRange.IsEmpty) { if (newRange.IsEmpty) {
return; return oldRange;
} }
if (newRange.Start <= this.StartILOffset) { if (newRange.Start <= oldRange.Start) {
if (newRange.End < this.StartILOffset) { if (newRange.End < oldRange.Start) {
this.ILRange = newRange; // use the earlier range return newRange; // use the earlier range
} else { } else {
// join overlapping ranges // join overlapping ranges
this.ILRange = new Interval(newRange.Start, Math.Max(newRange.End, this.ILRange.End)); return new Interval(newRange.Start, Math.Max(newRange.End, oldRange.End));
} }
} else if (newRange.Start <= this.ILRange.End) { } else if (newRange.Start <= oldRange.End) {
// join overlapping ranges // join overlapping ranges
this.ILRange = new Interval(this.StartILOffset, Math.Max(newRange.End, this.ILRange.End)); return new Interval(oldRange.Start, Math.Max(newRange.End, oldRange.End));
} }
return oldRange;
} }
public void AddILRange(ILInstruction sourceInstruction) public void AddILRange(ILInstruction sourceInstruction)

13
ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs

@ -19,6 +19,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.IL namespace ICSharpCode.Decompiler.IL
{ {
@ -175,6 +176,18 @@ namespace ICSharpCode.Decompiler.IL
output.Write(' '); output.Write(' ');
body.WriteTo(output, options); body.WriteTo(output, options);
} }
/// <summary>
/// Gets the ILRange of the instructions at the start of the catch-block,
/// that take the exception object and store it in the exception variable slot.
/// Note: This range is empty, if Filter is not empty, i.e., ldloc 1.
/// </summary>
public Interval ExceptionSpecifierILRange { get; private set; }
public void AddExceptionSpecifierILRange(Interval newRange)
{
ExceptionSpecifierILRange = CombineILRange(ExceptionSpecifierILRange, newRange);
}
} }
partial class TryFinally partial class TryFinally

14
ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

@ -17,10 +17,12 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.IL.Transforms namespace ICSharpCode.Decompiler.IL.Transforms
{ {
@ -692,7 +694,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
TransformCatchWhen(inst, filterContainer.EntryPoint); TransformCatchWhen(inst, filterContainer.EntryPoint);
} }
if (inst.Body is BlockContainer catchContainer) if (inst.Body is BlockContainer catchContainer)
TransformCatchVariable(inst, catchContainer.EntryPoint); TransformCatchVariable(inst, catchContainer.EntryPoint, isCatchBlock: true);
} }
/// <summary> /// <summary>
@ -709,7 +711,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// } /// }
/// } /// }
/// </summary> /// </summary>
void TransformCatchVariable(TryCatchHandler handler, Block entryPoint) void TransformCatchVariable(TryCatchHandler handler, Block entryPoint, bool isCatchBlock)
{ {
if (!handler.Variable.IsSingleDefinition || handler.Variable.LoadCount != 1) if (!handler.Variable.IsSingleDefinition || handler.Variable.LoadCount != 1)
return; // handle.Variable already has non-trivial uses return; // handle.Variable already has non-trivial uses
@ -720,6 +722,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (inlinedUnboxAny.Type.Equals(handler.Variable.Type)) { if (inlinedUnboxAny.Type.Equals(handler.Variable.Type)) {
context.Step("TransformCatchVariable - remove inlined UnboxAny", inlinedUnboxAny); context.Step("TransformCatchVariable - remove inlined UnboxAny", inlinedUnboxAny);
inlinedUnboxAny.ReplaceWith(inlinedUnboxAny.Argument); inlinedUnboxAny.ReplaceWith(inlinedUnboxAny.Argument);
foreach (var range in inlinedUnboxAny.ILRanges)
handler.AddExceptionSpecifierILRange(range);
} }
} }
return; return;
@ -746,6 +750,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
exceptionVar.Kind = VariableKind.ExceptionLocal; exceptionVar.Kind = VariableKind.ExceptionLocal;
exceptionVar.Type = handler.Variable.Type; exceptionVar.Type = handler.Variable.Type;
handler.Variable = exceptionVar; handler.Variable = exceptionVar;
if (isCatchBlock) {
foreach (var offset in entryPoint.Instructions[0].Descendants.SelectMany(o => o.ILRanges))
handler.AddExceptionSpecifierILRange(offset);
}
entryPoint.Instructions.RemoveAt(0); entryPoint.Instructions.RemoveAt(0);
} }
@ -754,7 +762,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// </summary> /// </summary>
void TransformCatchWhen(TryCatchHandler handler, Block entryPoint) void TransformCatchWhen(TryCatchHandler handler, Block entryPoint)
{ {
TransformCatchVariable(handler, entryPoint); TransformCatchVariable(handler, entryPoint, isCatchBlock: false);
if (entryPoint.Instructions.Count == 1 && entryPoint.Instructions[0].MatchLeave(out _, out var condition)) { if (entryPoint.Instructions.Count == 1 && entryPoint.Instructions[0].MatchLeave(out _, out var condition)) {
context.Step("TransformCatchWhen", entryPoint.Instructions[0]); context.Step("TransformCatchWhen", entryPoint.Instructions[0]);
handler.Filter = condition; handler.Filter = condition;

Loading…
Cancel
Save