Skip to content
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
59 changes: 34 additions & 25 deletions src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,19 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
break;

case ILOpcode.dup:
{
if (stack.Count == 0)
{
ThrowHelper.ThrowInvalidProgramException();
}
stack.Push(stack.Peek());

StackEntry entry = stack.Peek();
if (entry.ValueKind is not StackValueKind.ByRef and not StackValueKind.ObjRef)
entry = new StackEntry(entry.ValueKind, entry.Value.Clone());

stack.Push(entry);
break;
}

case ILOpcode.pop:
{
Expand Down Expand Up @@ -1690,6 +1697,9 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
if (type.IsNullable)
return Status.Fail(methodIL.OwningMethod, opcode);

if (((DefType)type).ContainsGCPointers)
return Status.Fail(methodIL.OwningMethod, opcode, "GC pointers");
Comment thread
MichalStrehovsky marked this conversation as resolved.

Comment thread
MichalStrehovsky marked this conversation as resolved.
if (type.RequiresAlign8())
return Status.Fail(methodIL.OwningMethod, opcode, "Align8");

Expand Down Expand Up @@ -1766,29 +1776,16 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
case ILOpcode.stind_i4:
case ILOpcode.stind_i8:
{
if (opcode == ILOpcode.stobj)
{
TypeDesc type = methodIL.GetObject(reader.ReadILToken()) as TypeDesc;
opcode = type.Category switch
{
TypeFlags.SByte or TypeFlags.Boolean or TypeFlags.Byte => ILOpcode.stind_i1,
TypeFlags.Int16 or TypeFlags.Char or TypeFlags.UInt16 => ILOpcode.stind_i2,
TypeFlags.Int32 or TypeFlags.UInt32 => ILOpcode.stind_i4,
TypeFlags.Int64 or TypeFlags.UInt64 => ILOpcode.stind_i8,
TypeFlags.IntPtr or TypeFlags.UIntPtr => ILOpcode.stind_i,
_ => ILOpcode.stobj,
};
}

Value val = opcode switch
TypeDesc type = opcode switch
{
ILOpcode.stind_i1 => stack.PopIntoLocation(context.GetWellKnownType(WellKnownType.Byte)),
ILOpcode.stind_i2 => stack.PopIntoLocation(context.GetWellKnownType(WellKnownType.UInt16)),
ILOpcode.stind_i4 => stack.PopIntoLocation(context.GetWellKnownType(WellKnownType.UInt32)),
ILOpcode.stind_i8 => stack.PopIntoLocation(context.GetWellKnownType(WellKnownType.UInt64)),
ILOpcode.stind_i => stack.PopIntoLocation(context.GetWellKnownType(WellKnownType.UIntPtr)),
_ => stack.Pop().Value
ILOpcode.stind_i1 => context.GetWellKnownType(WellKnownType.Byte),
ILOpcode.stind_i2 => context.GetWellKnownType(WellKnownType.UInt16),
ILOpcode.stind_i4 => context.GetWellKnownType(WellKnownType.UInt32),
ILOpcode.stind_i8 => context.GetWellKnownType(WellKnownType.UInt64),
ILOpcode.stind_i => context.GetWellKnownType(WellKnownType.UIntPtr),
_ /* stobj */ => (TypeDesc)methodIL.GetObject(reader.ReadILToken()),
};
Value val = stack.PopIntoLocation(type);

StackEntry location = stack.Pop();
if (location.ValueKind != StackValueKind.ByRef && location.ValueKind != StackValueKind.NativeInt)
Expand Down Expand Up @@ -1918,7 +1915,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V
{
var elementType = (MetadataType)method.Instantiation[0];
int elementSize = elementType.InstanceFieldSize.AsInt;
byte[] rvaData = Internal.TypeSystem.Ecma.EcmaFieldExtensions.GetFieldRvaData(createSpanEcmaField);
byte[] rvaData = GetFieldRvaData(createSpanEcmaField);
if (rvaData.Length % elementSize != 0)
return false;
retVal = new SpanValue(elementType, rvaData, 0, rvaData.Length);
Expand Down Expand Up @@ -1952,7 +1949,8 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V
&& isReferenceOrContainsReferencesType.Name == "RuntimeHelpers"u8 && isReferenceOrContainsReferencesType.Namespace == "System.Runtime.CompilerServices"u8
&& isReferenceOrContainsReferencesType.Module == method.Context.SystemModule:
{
bool result = method.Instantiation[0].IsGCPointer || (method.Instantiation[0] is DefType defType && defType.ContainsGCPointers);
bool result = method.Instantiation[0].IsGCPointer
|| (method.Instantiation[0] is DefType defType && (defType.ContainsGCPointers || defType.ContainsByRefs));
retVal = ValueTypeValue.FromSByte(result ? (sbyte)1 : (sbyte)0);
return true;
}
Expand Down Expand Up @@ -2910,7 +2908,7 @@ public override void WriteFieldData(ref ObjectDataBuilder builder, NodeFactory f
}
}

private sealed class SpanValue : BaseValueTypeValue, IInternalModelingOnlyValue
private sealed class SpanValue : BaseValueTypeValue, IInternalModelingOnlyValue, IAssignableValue
{
private readonly MetadataType _elementType;
private byte[] _bytes;
Expand Down Expand Up @@ -2957,6 +2955,17 @@ public override bool TryCreateByRef(out Value value)
return true;
}

bool IAssignableValue.TryAssign(Value value)
{
if (value is not SpanValue other || other._elementType != _elementType)
return false;

_bytes = other._bytes;
_index = other._index;
_length = other._length;
return true;
}

private sealed class SpanReferenceValue : ByRefValueBase, IHasInstanceFields
{
private readonly SpanValue _value;
Expand Down
Loading
Loading