Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asserts and GC holes with Unsafe.Subtract/ByteOffset #99019

Merged
merged 15 commits into from
Feb 29, 2024
2 changes: 1 addition & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9241,7 +9241,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
noway_assert(op1);
if (op1->IsCnsIntOrI())
{
noway_assert(varTypeIsIntOrI(tree));
noway_assert(varTypeIsIntegralOrI(tree));
EgorBo marked this conversation as resolved.
Show resolved Hide resolved

// The type of the new GT_NEG node cannot just be op2->TypeGet().
// Otherwise we may sign-extend incorrectly in cases where the GT_NEG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ public static void RefSubtract()

ref string r3 = ref Unsafe.Subtract(ref r2, 3);
Assert.Equal("abc", r3);

static ref byte NullTest(nuint offset) => ref Unsafe.Subtract(ref Unsafe.NullRef<byte>(), offset);
MichalPetryka marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(0, (nuint)Unsafe.AsPointer(ref NullTest(0)));
}

[Fact]
Expand Down
Loading