Browse Source

Merge remote-tracking branch 'origin/release/6.2' into master

pull/2157/head
Daniel Grunwald 5 years ago
parent
commit
2683079db6
  1. 9
      BuildTools/appveyor-ilspycmd-install.ps1
  2. 6
      BuildTools/appveyor-install.ps1
  3. 7
      BuildTools/pipelines-install.ps1
  4. 6
      BuildTools/update-assemblyinfo.ps1
  5. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  6. 6
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  7. 12
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/UnknownTypes.cs
  8. 59
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/UnknownTypes.il
  9. 8
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  10. 21
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  11. 3
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs
  12. 3
      ICSharpCode.Decompiler/IL/ILReader.cs
  13. 22
      ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs
  14. 2
      ILSpy/Properties/app.config.template
  15. 2
      appveyor.yml
  16. 8
      azure-pipelines.yml

9
BuildTools/appveyor-ilspycmd-install.ps1

@ -3,6 +3,9 @@ $ErrorActionPreference = "Stop" @@ -3,6 +3,9 @@ $ErrorActionPreference = "Stop"
$baseCommit = "e17b4bfedf4dc747b105396224cd726bdca500ad";
$baseCommitRev = 1;
# make sure this matches artifacts-only branches list in appveyor.yml!
$masterBranches = '^(master|release/.+)$';
$globalAssemblyInfoTemplateFile = "ILSpy/Properties/AssemblyInfo.template.cs";
$versionParts = @{};
@ -18,10 +21,10 @@ if ($versionName -ne "null") { @@ -18,10 +21,10 @@ if ($versionName -ne "null") {
} else {
$versionName = "";
}
if ($env:APPVEYOR_REPO_BRANCH -ne 'master') {
$branch = "-$env:APPVEYOR_REPO_BRANCH";
} else {
if ($env:APPVEYOR_REPO_BRANCH -match $masterBranches) {
$branch = "";
} else {
$branch = "-$env:APPVEYOR_REPO_BRANCH";
}
$revision = [Int32]::Parse((git rev-list --count "$baseCommit..HEAD")) + $baseCommitRev;

6
BuildTools/appveyor-install.ps1

@ -3,8 +3,8 @@ $ErrorActionPreference = "Stop" @@ -3,8 +3,8 @@ $ErrorActionPreference = "Stop"
$baseCommit = "d779383cb85003d6dabeb976f0845631e07bf463";
$baseCommitRev = 1;
# make sure this list matches artifacts-only branches list in appveyor.yml!
$masterBranches = @("master", "5.0.x");
# make sure this matches artifacts-only branches list in appveyor.yml!
$masterBranches = '^(master|release/.+)$';
$globalAssemblyInfoTemplateFile = "ILSpy/Properties/AssemblyInfo.template.cs";
@ -21,7 +21,7 @@ if ($versionName -ne "null") { @@ -21,7 +21,7 @@ if ($versionName -ne "null") {
} else {
$versionName = "";
}
if ($masterBranches -contains $env:APPVEYOR_REPO_BRANCH) {
if ($env:APPVEYOR_REPO_BRANCH -match $masterBranches) {
$branch = "";
} else {
$branch = "-$env:APPVEYOR_REPO_BRANCH";

7
BuildTools/pipelines-install.ps1

@ -3,8 +3,8 @@ $ErrorActionPreference = "Stop" @@ -3,8 +3,8 @@ $ErrorActionPreference = "Stop"
$baseCommit = "d779383cb85003d6dabeb976f0845631e07bf463";
$baseCommitRev = 1;
# make sure this list matches artifacts-only branches list in azure-pipelines.yml!
$masterBranches = @("master", "5.0.x");
# make sure this matches artifacts-only branches list in appveyor.yml!
$masterBranches = '^refs/heads/(master|release/.+)$';
$globalAssemblyInfoTemplateFile = "ILSpy/Properties/AssemblyInfo.template.cs";
@ -21,7 +21,8 @@ if ($versionName -ne "null") { @@ -21,7 +21,8 @@ if ($versionName -ne "null") {
} else {
$versionName = "";
}
if ($masterBranches -contains $env:BUILD_SOURCEBRANCHNAME) {
if ($env:BUILD_SOURCEBRANCH -match $masterBranches) {
$branch = "";
} else {
$branch = "-$env:BUILD_SOURCEBRANCHNAME";

6
BuildTools/update-assemblyinfo.ps1

@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
$baseCommit = "d779383cb85003d6dabeb976f0845631e07bf463";
$baseCommitRev = 1;
# make sure this list matches artifacts-only branches list in appveyor.yml!
$masterBranches = @("master", "5.0.x");
# make sure this matches artifacts-only branches list in appveyor.yml!
$masterBranches = '^(master|release/.+)$';
$globalAssemblyInfoTemplateFile = "ILSpy/Properties/AssemblyInfo.template.cs";
@ -112,7 +112,7 @@ try { @@ -112,7 +112,7 @@ try {
$branchName = gitBranch;
$gitCommitHash = gitCommitHash;
if ($masterBranches -contains $branchName) {
if ($branchName -match $masterBranches) {
$postfixBranchName = "";
} else {
$postfixBranchName = "-$branchName";

2
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -65,6 +65,8 @@ @@ -65,6 +65,8 @@
<None Include="TestCases\Correctness\StackTests.il" />
<None Include="TestCases\Correctness\StackTypes.il" />
<None Include="TestCases\Correctness\Uninit.vb" />
<None Include="TestCases\ILPretty\UnknownTypes.cs" />
<None Include="TestCases\ILPretty\UnknownTypes.il" />
<None Include="TestCases\ILPretty\EvalOrder.cs" />
<None Include="TestCases\ILPretty\EvalOrder.il" />
<None Include="TestCases\ILPretty\CallIndirect.il" />

6
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -146,6 +146,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -146,6 +146,12 @@ namespace ICSharpCode.Decompiler.Tests
Run(settings: new DecompilerSettings { SwitchExpressions = false });
}
[Test]
public void UnknownTypes()
{
Run();
}
[Test]
public void Issue1145()
{

12
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/UnknownTypes.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
internal class UnknownTypes
{
private readonly IInterface memberField;
public override bool CanExecute(CallbackQuery message)
{
return ((IInterface<SomeClass, bool>)(object)memberField).Execute(new SomeClass {
ChatId = StaticClass.GetChatId(message),
MessageId = StaticClass.GetMessageId(message)
});
}
}

59
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/UnknownTypes.il

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
#define CORE_ASSEMBLY "System.Runtime"
.assembly extern CORE_ASSEMBLY
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
.ver 4:0:0:0
}
.assembly extern UnknownAssembly
{
.publickeytoken = (01 02 03 04 05 06 07 08 )
.ver 1:0:0:0
}
.class private auto ansi beforefieldinit UnknownTypes
extends [System.Private.CoreLib]System.Object
{
.field private initonly class [UnknownAssembly]IInterface memberField
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x206e
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [CORE_ASSEMBLY]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method UnknownTypes::.ctor
.method public hidebysig virtual
instance bool CanExecute (
class [UnknownAssembly]CallbackQuery message
) cil managed
{
// Method begins at RVA 0x4dbc
// Code size 44 (0x2c)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class [UnknownAssembly]IInterface UnknownTypes::memberField
IL_0006: newobj instance void [UnknownAssembly]SomeClass::.ctor()
IL_000b: dup
IL_000d: ldarg.1
IL_000e: call int64 [UnknownAssembly]StaticClass::GetChatId(class [UnknownAssembly]CallbackQuery)
IL_0013: stfld int64 [UnknownAssembly]SomeClass::ChatId
IL_0018: dup
IL_001a: ldarg.1
IL_001b: call int32 [UnknownAssembly]StaticClass::GetMessageId(class [UnknownAssembly]CallbackQuery)
IL_0020: conv.i8
IL_0021: stfld int64 [UnknownAssembly]SomeClass::MessageId
IL_0026: callvirt instance !1 class [UnknownAssembly]IInterface`2<class [UnknownAssembly]SomeClass, bool>::Execute(!0)
IL_002b: ret
} // end of method CanExecute
} // end of class UnknownTypes

8
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -286,8 +286,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -286,8 +286,8 @@ namespace ICSharpCode.Decompiler.CSharp
var methodSemantics = module.MethodSemanticsLookup.GetSemantics(methodHandle).Item2;
if (methodSemantics != 0 && methodSemantics != System.Reflection.MethodSemanticsAttributes.Other)
return true;
if (LocalFunctionDecompiler.IsLocalFunctionMethod(module, methodHandle))
return settings.LocalFunctions;
if (settings.LocalFunctions && LocalFunctionDecompiler.IsLocalFunctionMethod(module, methodHandle))
return true;
if (settings.AnonymousMethods && methodHandle.HasGeneratedName(metadata) && methodHandle.IsCompilerGenerated(metadata))
return true;
if (settings.AsyncAwait && AsyncAwaitDecompiler.IsCompilerGeneratedMainMethod(module, methodHandle))
@ -299,8 +299,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -299,8 +299,8 @@ namespace ICSharpCode.Decompiler.CSharp
name = metadata.GetString(type.Name);
if (!type.GetDeclaringType().IsNil)
{
if (LocalFunctionDecompiler.IsLocalFunctionDisplayClass(module, typeHandle))
return settings.LocalFunctions;
if (settings.LocalFunctions && LocalFunctionDecompiler.IsLocalFunctionDisplayClass(module, typeHandle))
return true;
if (settings.AnonymousMethods && IsClosureType(type, metadata))
return true;
if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(typeHandle, metadata))

21
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -168,16 +168,19 @@ namespace ICSharpCode.Decompiler.CSharp @@ -168,16 +168,19 @@ namespace ICSharpCode.Decompiler.CSharp
}
else if (inst is ILiftableInstruction liftable && liftable.IsLifted)
{
Debug.Assert(NullableType.IsNullable(cexpr.Type));
IType underlying = NullableType.GetUnderlyingType(cexpr.Type);
if (liftable.UnderlyingResultType.IsIntegerType())
if (liftable.UnderlyingResultType != StackType.Unknown)
{
Debug.Assert(underlying.GetStackType().IsIntegerType(), "IL instructions of integer type must convert into C# expressions of integer type");
Debug.Assert(underlying.GetSign() != Sign.None, "Must have a sign specified for zero/sign-extension");
}
else
{
Debug.Assert(underlying.GetStackType() == liftable.UnderlyingResultType);
Debug.Assert(NullableType.IsNullable(cexpr.Type));
IType underlying = NullableType.GetUnderlyingType(cexpr.Type);
if (liftable.UnderlyingResultType.IsIntegerType())
{
Debug.Assert(underlying.GetStackType().IsIntegerType(), "IL instructions of integer type must convert into C# expressions of integer type");
Debug.Assert(underlying.GetSign() != Sign.None, "Must have a sign specified for zero/sign-extension");
}
else
{
Debug.Assert(underlying.GetStackType() == liftable.UnderlyingResultType);
}
}
}
else if (inst.ResultType == StackType.Ref)

3
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -502,7 +502,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -502,7 +502,8 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(new ByReferenceResolveResult(elementRR, ReferenceKind.Ref));
}
if (this.ResolveResult.IsCompileTimeConstant && this.ResolveResult.ConstantValue != null
&& NullableType.IsNullable(targetType) && !utype.Equals(targetUType))
&& NullableType.IsNullable(targetType) && !utype.Equals(targetUType)
&& targetUType.GetStackType().IsIntegerType())
{
// Casts like `(uint?)-1` are only valid in an explicitly unchecked context, but we
// don't have logic to ensure such a context (usually we emit into an implicitly unchecked context).

3
ICSharpCode.Decompiler/IL/ILReader.cs

@ -1312,7 +1312,8 @@ namespace ICSharpCode.Decompiler.IL @@ -1312,7 +1312,8 @@ namespace ICSharpCode.Decompiler.IL
return PopPointer();
default:
// field in unresolved type
if (PeekStackType() == StackType.O)
var stackType = PeekStackType();
if (stackType == StackType.O || stackType == StackType.Unknown)
return Pop();
else
return PopPointer();

22
ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs

@ -213,6 +213,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -213,6 +213,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var values = new List<(string, ILInstruction)>();
var uniqueValues = new HashSet<string>();
int numberOfUniqueMatchesWithCurrentVariable = 0;
HashSet<Block> caseBlocks = new HashSet<Block>();
caseBlocks.Add((Block)instructions[i].Parent);
bool AddSwitchSection(string value, ILInstruction inst)
{
@ -308,6 +310,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -308,6 +310,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (!AddSwitchSection(value, block))
return false;
}
caseBlocks.Add(currentCaseBlock);
currentCaseBlock = nextCaseBlock as Block;
} while (currentCaseBlock != null);
@ -316,7 +319,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -316,7 +319,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false;
context.Step(nameof(SimplifyCascadingIfStatements), instructions[i]);
// if the switchValueVar is used in other places as well, do not eliminate the store.
if (switchValueVar.LoadCount > numberOfUniqueMatchesWithCurrentVariable)
if (switchValueVar.LoadCount > numberOfUniqueMatchesWithCurrentVariable || !ValidateUsesOfSwitchValueVariable(switchValueVar, caseBlocks))
{
keepAssignmentBefore = true;
removeExtraLoad = false; // prevent loads from being deleted after detecting that
@ -355,6 +358,23 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -355,6 +358,23 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true;
}
private bool ValidateUsesOfSwitchValueVariable(ILVariable switchValueVar, HashSet<Block> caseBlocks)
{
foreach (var use in switchValueVar.LoadInstructions)
{
bool isValid = false;
foreach (var caseBlock in caseBlocks)
{
if (use.IsDescendantOf(caseBlock))
isValid = true;
}
if (!isValid)
return false;
}
return true;
}
bool SimplifyCSharp1CascadingIfStatements(InstructionCollection<ILInstruction> instructions, ref int i)
{
if (i < 1)

2
ILSpy/Properties/app.config.template

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="ICSharpCode.AvalonEdit" publicKeyToken="9cc39be672370310" culture="neutral"/>
<bindingRedirect oldVersion="4.1.0.0-99.9.9.9" newVersion="6.0"/>
<bindingRedirect oldVersion="4.1.0.0-99.9.9.9" newVersion="6.1.0.314"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="ICSharpCode.Decompiler" publicKeyToken="d4bfe873e7598c49" culture="neutral"/>

2
appveyor.yml

@ -45,7 +45,7 @@ for: @@ -45,7 +45,7 @@ for:
- branches:
only:
- master
- 5.0.x
- /release\/*/
artifacts:
- path: ILSpy_binaries.zip
name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries

8
azure-pipelines.yml

@ -1,10 +1,10 @@ @@ -1,10 +1,10 @@
trigger:
- master
- 5.0.x
- release/*
pr:
- master
- 5.0.x
- release/*
variables:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
@ -52,7 +52,7 @@ jobs: @@ -52,7 +52,7 @@ jobs:
inputs:
command: 'custom'
custom: 'tool'
arguments: 'install dotnet-format --tool-path BuildTools'
arguments: 'install dotnet-format --tool-path $(Agent.ToolsDirectory)/dotnet-format'
- script: pwsh .\BuildTools\pipelines-install.ps1
displayName: Install
@ -94,7 +94,7 @@ jobs: @@ -94,7 +94,7 @@ jobs:
- script: python BuildTools\tidy.py
displayName: Tab check
- script: .\BuildTools\dotnet-format --check --verbosity diagnostic ILSpy.sln
- script: $(Agent.ToolsDirectory)\dotnet-format\dotnet-format --check --verbosity diagnostic ILSpy.sln
displayName: dotnet-format check
- task: CopyFiles@2

Loading…
Cancel
Save