diff options
author | Morgan Brown <morganbr@users.noreply.github.com> | 2018-04-25 03:51:05 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-04-25 03:51:05 +0300 |
commit | 33b606d994109006c454e9846e4b549a4509018b (patch) | |
tree | 9068eb7516615af5b486027d6e6d1e9ee5229068 /src/ILCompiler.WebAssembly | |
parent | 967bcfe73db4d76202f4d0bb8f05ecf09b00dd83 (diff) |
Fix issues related to WebAssembly interface dispatch: (#5735)
1. Don't add a vtable offset to interface slot numbers
2. Ensure values are loaded before applying conv to them to avoid loading too wide of a value (found when interface dispatch loads a uint16 and then converts to IntPtr)
Diffstat (limited to 'src/ILCompiler.WebAssembly')
-rw-r--r-- | src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs | 22 | ||||
-rw-r--r-- | src/ILCompiler.WebAssembly/src/Compiler/DependencyAnalysis/WebAssemblyVTableSlotNode.cs | 11 |
2 files changed, 14 insertions, 19 deletions
diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs index f49035bde..c3ead694d 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs @@ -2015,26 +2015,12 @@ namespace Internal.IL private void ImportConvert(WellKnownType wellKnownType, bool checkOverflow, bool unsigned) { StackEntry value = _stack.Pop(); - LLVMValueRef convertedValue; TypeDesc destType = GetWellKnownType(wellKnownType); - //conv.u for a pointer should change to a int8* - if (wellKnownType == WellKnownType.UIntPtr) - { - if (value.Kind == StackValueKind.Int32) - { - convertedValue = LLVM.BuildIntToPtr(_builder, value.ValueAsInt32(_builder, false), LLVM.PointerType(LLVM.Int8Type(), 0), "conv.u"); - } - else - { - convertedValue = value.ValueAsType(destType, _builder); - } - } - else - { - convertedValue = value.ValueAsType(destType, _builder); - } - PushExpression(GetStackValueKind(destType), "conv", convertedValue, destType); + // Load the value and then convert it instead of using ValueAsType to avoid loading the incorrect size + LLVMValueRef loadedValue = value.ValueAsType(value.Type, _builder); + LLVMValueRef converted = CastIfNecessary(loadedValue, GetLLVMTypeForTypeDesc(destType)); + PushExpression(GetStackValueKind(destType), "conv", converted, destType); } private void ImportUnaryOperation(ILOpcode opCode) diff --git a/src/ILCompiler.WebAssembly/src/Compiler/DependencyAnalysis/WebAssemblyVTableSlotNode.cs b/src/ILCompiler.WebAssembly/src/Compiler/DependencyAnalysis/WebAssemblyVTableSlotNode.cs index e48163267..c9924f68a 100644 --- a/src/ILCompiler.WebAssembly/src/Compiler/DependencyAnalysis/WebAssemblyVTableSlotNode.cs +++ b/src/ILCompiler.WebAssembly/src/Compiler/DependencyAnalysis/WebAssemblyVTableSlotNode.cs @@ -61,7 +61,16 @@ namespace ILCompiler.DependencyAnalysis if (!relocsOnly) { - var tableOffset = EETypeNode.GetVTableOffset(factory.Target.PointerSize) / factory.Target.PointerSize; + int tableOffset; + if (_targetMethod.OwningType.IsInterface) + { + tableOffset = 0; + } + else + { + tableOffset = EETypeNode.GetVTableOffset(factory.Target.PointerSize) / factory.Target.PointerSize; + } + objData.EmitInt(tableOffset + VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, _targetMethod, _targetMethod.OwningType)); } return objData.ToObjectData(); |