Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed May 18, 2024
1 parent e841c63 commit 0bd0dcd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,14 @@ public static class PinnedAndUnpinnedLocalsToDecode
public static unsafe int DoSomething()
{
byte[] bytes = new byte[] { 1, 2, 3 };
Keep(ref bytes);
fixed (byte* bytePtr = bytes)
{
return *bytePtr;
}

// Reference local variables to prevent them from being optimized out by Roslyn
static void Keep<T>(ref T value) { };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,18 @@ private static int MyOtherMethod(int x)
public static void MyOtherMethod(object arg)
{
int var1 = 2;
Keep(ref var1);

string var2 = "I am a string";
Keep(ref var2);

if (arg == null)
{
throw new ArgumentNullException("Input arg cannot be null.");
}

// Reference local variables to prevent them from being optimized out by Roslyn
static void Keep<T>(ref T value) { };
}
#pragma warning restore xUnit1013 // Public method should be marked as test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter)
{
Assert.Equal(typeof(Exception), ehc.CatchType);
Assert.Equal(19, ehc.HandlerLength);
Assert.Equal(70, ehc.HandlerOffset);
Assert.Equal(26, ehc.HandlerLength);
Assert.Equal(84, ehc.HandlerOffset);
Assert.Equal(61, ehc.TryLength);
Assert.Equal(9, ehc.TryOffset);
Assert.Equal(23, ehc.TryOffset);
return;
}
}
Expand All @@ -64,10 +64,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter)
{
Assert.Equal(typeof(Exception), ehc.CatchType);
Assert.Equal(14, ehc.HandlerLength);
Assert.Equal(58, ehc.HandlerOffset);
Assert.Equal(21, ehc.HandlerLength);
Assert.Equal(72, ehc.HandlerOffset);
Assert.Equal(50, ehc.TryLength);
Assert.Equal(8, ehc.TryOffset);
Assert.Equal(22, ehc.TryOffset);
return;
}
}
Expand All @@ -79,7 +79,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
private static void MethodBodyExample(object arg)
{
int var1 = 2;
Keep(ref var1);

string var2 = "I am a string";
Keep(ref var2);

try
{
Expand All @@ -94,13 +97,17 @@ private static void MethodBodyExample(object arg)
}
catch (Exception ex)
{
Keep(ref ex);
Console.WriteLine(ex.Message);
}
finally
{
var1 = 3;
var2 = "I am a new string!";
}

// Reference local variables to prevent them from being optimized out by Roslyn
static void Keep<T>(ref T value) { };
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="InlineArrayInvalid.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Loader/classloader/RefFields/Validate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MonoAotIncompatible>true</MonoAotIncompatible>
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="Validate.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="ManagedPointers.cs" />
Expand Down

0 comments on commit 0bd0dcd

Please sign in to comment.