From ebb9fdd79dfebed3a05a68a8be390b89607a469d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 12 Jun 2016 09:12:11 +0900 Subject: [PATCH] do not generate unused exception variables, transform unused object-typed exception variables to catch-all --- ICSharpCode.Decompiler/CSharp/StatementBuilder.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 856f428d5..ee4941407 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -163,9 +163,14 @@ namespace ICSharpCode.Decompiler.CSharp tryCatch.TryBlock = ConvertAsBlock(inst.TryBlock); foreach (var handler in inst.Handlers) { var catchClause = new CatchClause(); - if (handler.Variable != null) { - catchClause.Type = exprBuilder.ConvertType(handler.Variable.Type); - catchClause.VariableName = handler.Variable.Name; + var v = handler.Variable; + if (v != null) { + if (v.StoreCount > 1 || v.LoadCount > 0 || v.AddressCount > 0) { + catchClause.VariableName = v.Name; + catchClause.Type = exprBuilder.ConvertType(v.Type); + } else if (!v.Type.IsKnownType(KnownTypeCode.Object)) { + catchClause.Type = exprBuilder.ConvertType(v.Type); + } } if (!handler.Filter.MatchLdcI4(1)) catchClause.Condition = exprBuilder.TranslateCondition(handler.Filter);