diff options
author | Jeff Greene <hippiehunterenator@gmail.com> | 2018-05-11 01:39:48 +0300 |
---|---|---|
committer | Morgan Brown <morganbr@users.noreply.github.com> | 2018-05-11 01:39:48 +0300 |
commit | 832b86f06850fa1faa349dc3302efc3151499046 (patch) | |
tree | c473c2899b3c97fe64912b0e154357dc08381510 /src/ILCompiler.WebAssembly | |
parent | 932f1d0788da1c2d60526d9896d9cb3aeafccd97 (diff) |
fix dup instruction result to no longer reference the original memory in WASM (#5784)
fix dup instruction result to no longer reference the original memory
added additional dup test cases
Diffstat (limited to 'src/ILCompiler.WebAssembly')
-rw-r--r-- | src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs | 26 | ||||
-rw-r--r-- | src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs | 12 |
2 files changed, 20 insertions, 18 deletions
diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs b/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs index 92c191976..fb510889a 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/EvaluationStack.cs @@ -239,7 +239,7 @@ namespace Internal.IL /// Create a new copy of current entry. /// </summary> /// <returns>A new instance of the same type as the current entry.</returns> - public abstract StackEntry Duplicate(); + public abstract StackEntry Duplicate(LLVMBuilderRef builder); } /// <summary> @@ -298,7 +298,7 @@ namespace Internal.IL } } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return new Int32ConstantEntry(Value, Type); } @@ -333,7 +333,7 @@ namespace Internal.IL { } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return new Int64ConstantEntry(Value, Type); } @@ -397,7 +397,7 @@ namespace Internal.IL return LLVM.ConstReal(type, Value); } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return new FloatConstantEntry(Value, Type); } @@ -425,7 +425,7 @@ namespace Internal.IL RawLLVMValue = llvmValue; } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return new ExpressionEntry(Kind, Name, RawLLVMValue, Type); } @@ -449,9 +449,9 @@ namespace Internal.IL { } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { - return new LoadExpressionEntry(Kind, Name, RawLLVMValue, Type); + return new ExpressionEntry(Kind, "duplicate_" + Name, ILImporter.LoadValue(builder, RawLLVMValue, Type, ILImporter.GetLLVMTypeForTypeDesc(Type), false, "load_duplicate_" + Name), Type); } protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend) @@ -472,9 +472,9 @@ namespace Internal.IL { } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { - return new LoadExpressionEntry(Kind, Name, RawLLVMValue, Type); + return new AddressExpressionEntry(Kind, Name, RawLLVMValue, Type); } protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend) @@ -501,7 +501,7 @@ namespace Internal.IL IsVirtual = isVirtual; } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return new FunctionPointerEntry(Name, Method, RawLLVMValue, Type, IsVirtual); } @@ -519,7 +519,7 @@ namespace Internal.IL LdToken = token; } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return new LdTokenEntry<T>(Kind, Name, LdToken, RawLLVMValue, Type); } @@ -544,7 +544,7 @@ namespace Internal.IL { } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return this; } @@ -576,7 +576,7 @@ namespace Internal.IL return ILImporter.CastIfNecessary(builder, value, type); } - public override StackEntry Duplicate() + public override StackEntry Duplicate(LLVMBuilderRef builder) { return new SpilledExpressionEntry(Kind, Name, Type, LocalIndex, _importer); } diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs index d96ff3123..53d9d9e75 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs @@ -295,7 +295,7 @@ namespace Internal.IL int n = entryStack.Length; for (int i = 0; i < n; i++) { - _stack.Push(entryStack[i].Duplicate()); + _stack.Push(entryStack[i].Duplicate(_builder)); } } @@ -365,19 +365,19 @@ namespace Internal.IL LLVM.BuildStore(_builder, CastToTypeDesc(value, type), CastToPointerToTypeDesc(address, type)); } - internal static LLVMValueRef LoadValue(LLVMBuilderRef builder, LLVMValueRef address, TypeDesc sourceType, LLVMTypeRef targetType, bool signExtend) + internal static LLVMValueRef LoadValue(LLVMBuilderRef builder, LLVMValueRef address, TypeDesc sourceType, LLVMTypeRef targetType, bool signExtend, string loadName = null) { var underlyingSourceType = sourceType.UnderlyingType; if (targetType.TypeKind == LLVMTypeKind.LLVMIntegerTypeKind && underlyingSourceType.IsPrimitive && !underlyingSourceType.IsPointer) { var sourceLLVMType = ILImporter.GetLLVMTypeForTypeDesc(underlyingSourceType); var typedAddress = CastIfNecessary(builder, address, LLVM.PointerType(sourceLLVMType, 0)); - return CastIntValue(builder, LLVM.BuildLoad(builder, typedAddress, "ldvalue"), targetType, signExtend); + return CastIntValue(builder, LLVM.BuildLoad(builder, typedAddress, loadName ?? "ldvalue"), targetType, signExtend); } else { var typedAddress = CastIfNecessary(builder, address, LLVM.PointerType(targetType, 0)); - return LLVM.BuildLoad(builder, typedAddress, "ldvalue"); + return LLVM.BuildLoad(builder, typedAddress, loadName ?? "ldvalue"); } } @@ -836,7 +836,9 @@ namespace Internal.IL private void ImportDup() { - _stack.Push(_stack.Peek().Duplicate()); + var entry = _stack.Pop(); + _stack.Push(entry.Duplicate(_builder)); + _stack.Push(entry.Duplicate(_builder)); } private void ImportPop() |