Browse Source

Improve inlining of boxed values

pull/3587/head
ds5678 3 months ago
parent
commit
ad4a87b9a3
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 47
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue3584.cs
  4. 2
      ICSharpCode.Decompiler/IL/ILTypeExtensions.cs
  5. 12
      ICSharpCode.Decompiler/IL/Instructions.cs

1
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -163,6 +163,7 @@ @@ -163,6 +163,7 @@
<Compile Include="TestCases\Pretty\Issue3571_B.cs" />
<Compile Include="TestCases\Pretty\Issue3571_A.cs" />
<Compile Include="TestCases\Pretty\Issue3576.cs" />
<Compile Include="TestCases\Pretty\Issue3584.cs" />
<Compile Include="TestCases\Pretty\PlaystationPreferPrimary.cs" />
<Compile Include="TestCases\Pretty\Playstation.cs" />
<None Include="TestCases\Ugly\NoLocalFunctions.Expected.cs" />

6
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -718,6 +718,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -718,6 +718,12 @@ namespace ICSharpCode.Decompiler.Tests
await RunForLibrary(cscOptions: cscOptions);
}
[Test]
public async Task Issue3584([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions);
}
[Test]
public async Task AssemblyCustomAttributes([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{

47
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue3584.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal abstract class Issue4000<T> : IEnumerable<T>, IEnumerable
{
public int Length;
protected T[] results;
#if !ROSLYN4
public T this[int i] {
get {
if (i >= Length || i < 0)
{
return default(T);
}
if (results[i] != null && results[i].Equals(default(T)))
{
results[i] = CreateIthElement(i);
}
return results[i];
}
}
#endif
protected abstract T CreateIthElement(int i);
public IEnumerator<T> GetEnumerator()
{
for (int i = 0; i < Length; i++)
{
if (results[i] != null && results[i].Equals(default(T)))
{
results[i] = CreateIthElement(i);
}
yield return results[i];
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

2
ICSharpCode.Decompiler/IL/ILTypeExtensions.cs

@ -238,6 +238,8 @@ namespace ICSharpCode.Decompiler.IL @@ -238,6 +238,8 @@ namespace ICSharpCode.Decompiler.IL
default:
return SpecialType.UnknownType;
}
case DefaultValue defaultValue:
return defaultValue.Type;
case ILFunction func when func.DelegateType != null:
return func.DelegateType;
default:

12
ICSharpCode.Decompiler/IL/Instructions.cs

@ -318,6 +318,7 @@ namespace ICSharpCode.Decompiler.IL @@ -318,6 +318,7 @@ namespace ICSharpCode.Decompiler.IL
set {
ValidateChild(value);
SetChildInstruction(ref this.argument, value, 0);
InvalidateFlags();
}
}
protected sealed override int GetChildCount()
@ -4357,10 +4358,19 @@ namespace ICSharpCode.Decompiler.IL @@ -4357,10 +4358,19 @@ namespace ICSharpCode.Decompiler.IL
public override StackType ResultType { get { return StackType.O; } }
protected override InstructionFlags ComputeFlags()
{
return base.ComputeFlags() | InstructionFlags.SideEffect | InstructionFlags.MayThrow;
var baseFlags = base.ComputeFlags();
if (baseFlags == InstructionFlags.None && Type.Equals(Argument.InferType(null)))
{
return InstructionFlags.None;
}
return baseFlags | InstructionFlags.SideEffect | InstructionFlags.MayThrow;
}
public override InstructionFlags DirectFlags {
get {
if (Flags == InstructionFlags.None)
{
return InstructionFlags.None;
}
return base.DirectFlags | InstructionFlags.SideEffect | InstructionFlags.MayThrow;
}
}

Loading…
Cancel
Save