forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark certain compiler-created locals as aliased (dotnet#74665)
* Add a test for the devirt case * Fix the devirt case * Add a test for the ctor case * Fix the ctor case * Add a test for the localloc case This one is actually ok, but only because "gtNewFieldRef" is quirky. * Fix the localloc case * Add an assert to catch future violations * Fix up "arglist" * Add a more elaborate "newobj" test case One might be tempted to say that a "newobj" temp isn't really aliased, since it is atomically assigned by the constructor call. As this new test case shows, such is not the case - the "this" address pointing to the local being constructed can be captured and used to mutate it.
- Loading branch information
1 parent
81f8e64
commit ba32931
Showing
5 changed files
with
255 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
210 changes: 210 additions & 0 deletions
210
src/tests/JIT/Regression/JitBlue/Runtime_74635/Runtime_74635.il
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
.assembly extern System.Runtime { } | ||
.assembly extern System.Console { } | ||
|
||
.assembly Runtime_74635.dll { } | ||
|
||
#define TRUE "1" | ||
#define FALSE "0" | ||
#define THIS "0" | ||
|
||
#define EXPECTED "0" | ||
#define THRASHED "1" | ||
|
||
.class Runtime_74635 extends [System.Runtime]System.Object | ||
{ | ||
.method public static int32 Main() | ||
{ | ||
.entrypoint | ||
|
||
call bool .this::ProblemWithDevirtualization() | ||
brtrue DEVIRT_FAILED | ||
|
||
call bool .this::ProblemWithCtors() | ||
brtrue CTORS_FAILED | ||
|
||
call bool .this::ProblemWithLocAlloc() | ||
brtrue LOCALLOC_FAILED | ||
|
||
call bool .this::ProblemWithCapturingCtors() | ||
brtrue CAPTURING_CTORS_FAILED | ||
|
||
ldc.i4 100 | ||
ret | ||
|
||
DEVIRT_FAILED: | ||
ldc.i4 101 | ||
ret | ||
|
||
CTORS_FAILED: | ||
ldc.i4 102 | ||
ret | ||
|
||
LOCALLOC_FAILED: | ||
ldc.i4 103 | ||
ret | ||
|
||
CAPTURING_CTORS_FAILED: | ||
ldc.i4 104 | ||
ret | ||
} | ||
|
||
.method private static bool ProblemWithDevirtualization() noinlining | ||
{ | ||
ldc.i4 EXPECTED | ||
newobj instance void Struct::.ctor(int32) | ||
box valuetype Struct | ||
callvirt instance int32 Interface::ReturnSelf() | ||
ldc.i4 EXPECTED | ||
bne.un FAILED | ||
|
||
ldc.i4 FALSE | ||
ret | ||
|
||
FAILED: | ||
ldc.i4 TRUE | ||
ret | ||
} | ||
|
||
.method private static bool ProblemWithCtors() noinlining | ||
{ | ||
ldc.i4 EXPECTED | ||
ldc.i4 THRASHED | ||
newobj instance void Struct::.ctor(int32, int32) | ||
pop | ||
|
||
ldsfld int32 Struct::StaticValue | ||
ldc.i4 EXPECTED | ||
bne.un FAILED | ||
|
||
ldc.i4 FALSE | ||
ret | ||
|
||
FAILED: | ||
ldc.i4 TRUE | ||
ret | ||
} | ||
|
||
.method private static bool ProblemWithLocAlloc() noinlining | ||
{ | ||
sizeof valuetype Struct | ||
localloc | ||
call int32 .this::ReturnExpectedWithLocAlloc(void*) | ||
ldc.i4 EXPECTED | ||
bne.un FAILED | ||
|
||
ldc.i4 FALSE | ||
ret | ||
|
||
FAILED: | ||
ldc.i4 TRUE | ||
ret | ||
} | ||
|
||
.method private static int32 ReturnExpectedWithLocAlloc(void* pLocAlloc) | ||
{ | ||
ldarg pLocAlloc | ||
ldc.i4 EXPECTED | ||
stind.i4 | ||
|
||
ldarg pLocAlloc | ||
ldfld int32 Struct::Value | ||
ldarg pLocAlloc | ||
ldc.i4 THRASHED | ||
stind.i4 | ||
ret | ||
} | ||
|
||
.method private static bool ProblemWithCapturingCtors() noinlining | ||
{ | ||
.locals (valuetype Closure closure) | ||
|
||
ldc.i4 EXPECTED | ||
ldloca closure | ||
newobj instance void Struct::.ctor(int32, valuetype Closure&) | ||
ldloc closure | ||
ldfld valuetype Struct& Closure::StructRef | ||
ldc.i4 THRASHED | ||
stfld int32 Struct::Value | ||
ldfld int32 Struct::Value | ||
ldc.i4 EXPECTED | ||
bne.un FAILED | ||
|
||
ldc.i4 FALSE | ||
ret | ||
|
||
FAILED: | ||
ldc.i4 TRUE | ||
ret | ||
} | ||
} | ||
|
||
.class interface Interface | ||
{ | ||
.method public abstract virtual int32 ReturnSelf() { } | ||
} | ||
|
||
.class sealed sequential Struct extends [System.Runtime]System.ValueType implements Interface | ||
{ | ||
.field public static int32 StaticValue | ||
|
||
.field public int32 Value | ||
|
||
.method public void .ctor(int32 val) | ||
{ | ||
ldarg THIS | ||
ldarg val | ||
stfld int32 .this::Value | ||
|
||
ret | ||
} | ||
|
||
.method public void .ctor(int32 expected, int32 thrashed) | ||
{ | ||
ldarg THIS | ||
ldarg expected | ||
stfld int32 .this::Value | ||
|
||
ldarg THIS | ||
ldfld int32 .this::Value | ||
ldarg THIS | ||
ldarg thrashed | ||
stind.i4 | ||
stsfld int32 .this::StaticValue | ||
|
||
ret | ||
} | ||
|
||
.method public void .ctor(int32 val, valuetype Closure& closureRef) noinlining | ||
{ | ||
ldarg THIS | ||
ldarg val | ||
stfld int32 .this::Value | ||
|
||
ldarg closureRef | ||
ldarg THIS | ||
stfld valuetype Struct& Closure::StructRef | ||
|
||
ret | ||
} | ||
|
||
.method public virtual int32 ReturnSelf() | ||
{ | ||
ldarg THIS | ||
ldfld int32 .this::Value | ||
ldarg THIS | ||
ldc.i4 THRASHED | ||
stind.i4 | ||
|
||
ret | ||
} | ||
} | ||
|
||
.class sealed Closure extends [System.Runtime]System.ValueType | ||
{ | ||
.custom instance void [System.Runtime]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = (01 00 00 00) | ||
|
||
.field public valuetype Struct& StructRef | ||
} |
11 changes: 11 additions & 0 deletions
11
src/tests/JIT/Regression/JitBlue/Runtime_74635/Runtime_74635.ilproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.IL"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).il" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters