Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Fixed ldind failure and properly zext unsigned types in WebAssembly #5342

Merged
merged 2 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ private static LLVMValueRef CastIntValue(LLVMBuilderRef builder, LLVMValueRef va
{
return LLVM.BuildSExtOrBitCast(builder, value, type, "SExtOrBitCast");
}
else if (type.GetIntTypeWidth() > LLVM.TypeOf(value).GetIntTypeWidth())
{
return LLVM.BuildZExtOrBitCast(builder, value, type, "ZExtOrBitCast");
}
else
{
Debug.Assert(typeKind == LLVMTypeKind.LLVMIntegerTypeKind);
Expand Down Expand Up @@ -1569,7 +1573,7 @@ private void ImportLoadIndirect(TypeDesc type)

LLVMValueRef pointerElementType = pointer.ValueAsType(type.MakePointerType(), _builder);
_stack.Push(new LoadExpressionEntry(type != null ? GetStackValueKind(type) : StackValueKind.ByRef, "ldind",
pointerElementType, type.MakePointerType()));
pointerElementType, type));
}

private void ImportStoreIndirect(int token)
Expand Down
31 changes: 31 additions & 0 deletions tests/src/Simple/HelloWasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ private static unsafe void Main(string[] args)
{
PrintLine("Type casting with isinst & castclass to array test: Ok.");
}

ldindTest();

PrintLine("Done");
}
Expand Down Expand Up @@ -305,6 +307,35 @@ private static void IntToStringTest()
PrintLine(intString);
}

private unsafe static void ldindTest()
{
var ldindTarget = new TwoByteStr { first = byte.MaxValue, second = byte.MinValue };
var ldindField = &ldindTarget.first;
if((*ldindField) == byte.MaxValue)
{
ldindTarget.second = byte.MaxValue;
*ldindField = byte.MinValue;
//ensure there isnt any overwrite of nearby fields
if(ldindTarget.first == byte.MinValue && ldindTarget.second == byte.MaxValue)
{
PrintLine("ldind test: Ok.");
}
else if(ldindTarget.first != byte.MinValue)
{
PrintLine("ldind test: Failed didnt update target.");
}
else
{
PrintLine("ldind test: Failed overwrote data");
}
}
else
{
uint ldindFieldValue = *ldindField;
PrintLine("ldind test: Failed." + ldindFieldValue.ToString());
}
}

[DllImport("*")]
private static unsafe extern int printf(byte* str, byte* unused);
}
Expand Down