Skip to content
Open
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
30 changes: 24 additions & 6 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,16 @@ bool Compiler::optIsTreeKnownIntValue(bool vnBased, GenTree* tree, ssize_t* pCon
var_types vnType = vnStore->TypeOfVN(vn);
if (vnType == TYP_INT)
{
*pConstant = vnStore->ConstantValue<int>(vn);
*pFlags = vnStore->IsVNHandle(vn) ? vnStore->GetHandleFlags(vn) : GTF_EMPTY;
if (vnStore->IsVNHandle(vn))
{
*pConstant = vnStore->ConstantValue<ssize_t>(vn);
*pFlags = vnStore->GetHandleFlags(vn);
}
else
{
*pConstant = vnStore->ConstantValue<int>(vn);
*pFlags = GTF_EMPTY;
}
return true;
}
#ifdef TARGET_64BIT
Expand Down Expand Up @@ -4600,12 +4608,16 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
}
else
{
printf("%d (gcref)\n", static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)));
assert(vnStore->IsVNHandle(vnCns));
printf("%p (gcref)\n", dspPtr(vnStore->ConstantValue<ssize_t>(vnCns)));
}
}
else if (op1->TypeIs(TYP_BYREF))
{
printf("%d (byref)\n", static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)));
ssize_t constant = vnStore->IsVNHandle(vnCns)
? vnStore->ConstantValue<ssize_t>(vnCns)
: static_cast<ssize_t>(vnStore->ConstantValue<size_t>(vnCns));
printf("%p (byref)\n", dspPtr(constant));
}
else
{
Expand Down Expand Up @@ -4654,11 +4666,17 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
}
else if (op1->TypeIs(TYP_REF))
{
op1->BashToConst(static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)), TYP_REF);
ssize_t constant = vnStore->IsVNHandle(vnCns)
? vnStore->ConstantValue<ssize_t>(vnCns)
: static_cast<ssize_t>(vnStore->ConstantValue<size_t>(vnCns));
op1->BashToConst(constant, TYP_REF);
}
else if (op1->TypeIs(TYP_BYREF))
{
op1->BashToConst(static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)), TYP_BYREF);
ssize_t constant = vnStore->IsVNHandle(vnCns)
? vnStore->ConstantValue<ssize_t>(vnCns)
: static_cast<ssize_t>(vnStore->ConstantValue<size_t>(vnCns));
op1->BashToConst(constant, TYP_BYREF);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ void GenTree::BashToConst(T value, var_types type /* = TYP_UNDEF */)
assert(type != TYP_LONG);
#endif
assert(varTypeIsIntegral(type) || varTypeIsGC(type));
if (genTypeSize(type) <= genTypeSize(TYP_INT))
if (!varTypeIsGC(type) && (genTypeSize(type) <= genTypeSize(TYP_INT)))
{
assert(FitsIn<int32_t>(value));
}
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3983,8 +3983,9 @@ GenTree* Compiler::impImportStaticReadOnlyField(CORINFO_FIELD_HANDLE field, CORI
uint8_t buffer[bufferSize] = {0};
if (varTypeIsIntegral(fieldType) || varTypeIsFloating(fieldType) || (fieldType == TYP_REF))
{
assert(bufferSize >= genTypeSize(fieldType));
if (info.compCompHnd->getStaticFieldContent(field, buffer, genTypeSize(fieldType)))
const int fieldValueSize = (fieldType == TYP_REF) ? (int)sizeof(ssize_t) : genTypeSize(fieldType);
assert(bufferSize >= fieldValueSize);
if (info.compCompHnd->getStaticFieldContent(field, buffer, fieldValueSize))
{
Comment on lines +3986 to 3989
GenTree* cnsValue = gtNewGenericCon(fieldType, buffer);
if (cnsValue != nullptr)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ private object HandleToObject(void* handle)
{
Debug.Assert(handle != null);
#if DEBUG
Debug.Assert((s_handleHighBitSet & (nint)handle) != 0);
handle = (void*)(~s_handleHighBitSet & (nint)handle);
#endif
int index = ((int)handle - handleBase) / handleMultiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2346,13 +2346,15 @@ private bool getStaticFieldContent(CORINFO_FIELD_STRUCT_* fieldHandle, byte* buf
.GetPreinitializationInfo(owningType).GetFieldValue(field);

int targetPtrSize = _compilation.TypeSystemContext.Target.PointerSize;
bool isObjectHandleBuffer =
(valueOffset == 0) && ((bufferSize == targetPtrSize) || (bufferSize == sizeof(nint)));

if (value == null)
{
if ((valueOffset == 0) && (bufferSize == targetPtrSize))
if (isObjectHandleBuffer)
{
// Write "null" to buffer
new Span<byte>(buffer, targetPtrSize).Clear();
new Span<byte>(buffer, bufferSize).Clear();
return true;
}
else
Expand All @@ -2374,11 +2376,13 @@ private bool getStaticFieldContent(CORINFO_FIELD_STRUCT_* fieldHandle, byte* buf
return false;

case FrozenObjectNode:
if ((valueOffset == 0) && (bufferSize == targetPtrSize))
if (isObjectHandleBuffer)
{
// save handle's value to buffer
nint handle = ObjectToHandle(data);
new Span<byte>(&handle, targetPtrSize).CopyTo(new Span<byte>(buffer, targetPtrSize));
Span<byte> destination = new Span<byte>(buffer, bufferSize);
destination.Clear();
new ReadOnlySpan<byte>(&handle, Math.Min(sizeof(nint), bufferSize)).CopyTo(destination);
Comment on lines 2378 to +2385
return true;
}
return false;
Expand Down
1 change: 0 additions & 1 deletion src/tests/JIT/Methodical/jitinterface/bug603649.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class foo
private static object s_o = typeof(string);
[Fact]
[OuterLoop]
[ActiveIssue("https://github.com/dotnet/runtime/issues/122013", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot), nameof(TestLibrary.Utilities.Is32))]
public static int TestEntryPoint()
{
bool f = typeof(string) == s_o as Type;
Expand Down
5 changes: 1 addition & 4 deletions src/tests/Regressions/coreclr/15647/interfacestatics.ilproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<!-- Needed for TrimMode -->
<!-- Needed for CLRTestTargetUnsupported -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<!-- Partial trimming works around https://github.com/dotnet/runtime/issues/122013 -->
<TrimMode>partial</TrimMode>

<!-- https://github.com/dotnet/runtime/issues/34390 -->
<CLRTestTargetUnsupported Condition="'$(RuntimeFlavor)' == 'mono'">true</CLRTestTargetUnsupported>
</PropertyGroup>
Expand Down
Loading