Browse Source

Fix unit tests.

pull/1246/head
Siegfried Pammer 7 years ago
parent
commit
00194f8c03
  1. 4
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  2. 7
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

4
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -241,9 +241,6 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -241,9 +241,6 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
));
CompilerResults results = new CompilerResults(new TempFileCollection());
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
string systemMemoryDestPath = Path.Combine(Path.GetDirectoryName(results.PathToAssembly), Path.GetFileName(typeof(Span<>).Assembly.Location));
if (!File.Exists(systemMemoryDestPath))
File.Copy(typeof(Span<>).Assembly.Location, systemMemoryDestPath);
var emitResult = compilation.Emit(results.PathToAssembly);
if (!emitResult.Success) {
StringBuilder b = new StringBuilder("Compiler error:");
@ -406,6 +403,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -406,6 +403,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
var module = new PEFile(assemblyFileName, file, PEStreamOptions.PrefetchEntireImage);
var resolver = new UniversalAssemblyResolver(assemblyFileName, false,
module.Reader.DetectTargetFrameworkId(), PEStreamOptions.PrefetchMetadata);
resolver.AddSearchDirectory(Path.GetDirectoryName(typeof(Span<>).Assembly.Location));
var typeSystem = new DecompilerTypeSystem(module, resolver, settings);
CSharpDecompiler decompiler = new CSharpDecompiler(typeSystem, settings);
decompiler.AstTransforms.Insert(0, new RemoveEmbeddedAtttributes());

7
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2287,6 +2287,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2287,6 +2287,11 @@ namespace ICSharpCode.Decompiler.CSharp
throw new ArgumentException("given Block is invalid!");
StackAllocExpression stackAllocExpression;
IType elementType;
if (block.Instructions.Count < 2 || !block.Instructions[1].MatchStObj(out _, out _, out var t))
throw new ArgumentException("given Block is invalid!");
if (typeHint is PointerType pt && !TypeUtils.IsCompatibleTypeForMemoryAccess(t, pt.ElementType)) {
typeHint = new PointerType(t);
}
switch (stloc.Value) {
case LocAlloc locAlloc:
stackAllocExpression = TranslateLocAlloc(locAlloc, typeHint, out elementType);
@ -2303,7 +2308,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2303,7 +2308,7 @@ namespace ICSharpCode.Decompiler.CSharp
for (int i = 1; i < block.Instructions.Count; i++) {
// stobj type(binary.add.i(ldloc I_0, conv i4->i <sign extend> (ldc.i4 offset)), value)
if (!block.Instructions[i].MatchStObj(out var target, out var value, out var t) || !TypeUtils.IsCompatibleTypeForMemoryAccess(elementType, t))
if (!block.Instructions[i].MatchStObj(out var target, out var value, out t) || !TypeUtils.IsCompatibleTypeForMemoryAccess(elementType, t))
throw new ArgumentException("given Block is invalid!");
long offset = 0;
target = target.UnwrapConv(ConversionKind.StopGCTracking);

Loading…
Cancel
Save