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
2 changes: 2 additions & 0 deletions src/coreclr/tools/ILVerification/ILImporter.Verify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,8 @@ void ImportLocalAlloc()

var size = Pop();

Check(_stackTop == 0, VerifierError.LocallocStackNotEmpty);

CheckIsInteger(size);

Push(StackValue.CreatePrimitive(StackValueKind.NativeInt));
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/ILVerification/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,7 @@
<data name="InterfaceMethodNotImplemented" xml:space="preserve">
<value>Class implements interface but not method, Class: '{0}' Interface: '{1}' Missing method: '{2}'.</value>
</data>
<data name="LocallocStackNotEmpty" xml:space="preserve">
<value>Stack must be empty before localloc, except for the size item.</value>
</data>
</root>
3 changes: 2 additions & 1 deletion src/coreclr/tools/ILVerification/VerifierError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public enum VerifierError
//IDS_E_GLOBAL "<GlobalFunction>"
//IDS_E_MDTOKEN "[mdToken=0x%x]"
InterfaceImplHasDuplicate, // InterfaceImpl has a duplicate
InterfaceMethodNotImplemented // Class implements interface but not method
InterfaceMethodNotImplemented, // Class implements interface but not method
LocallocStackNotEmpty, // localloc requires that stack must be empty, except for 'size' argument
}
}
2 changes: 1 addition & 1 deletion src/tests/ilverify/ILTests/DefaultInterfaceMethod.il
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
}
}

.class public auto ansi beforefieldinit ChildClassInheritsFromInterfaceWithDefaultImplementationWhereChildInterfaceReabstractsInterfaceMethod_InvalidType_InterfaceMethodNotImplemented
.class public auto ansi beforefieldinit ChildClassInheritsFromInterfaceWithDefaultImplementationWhereChildInterfaceReabstractsInterfaceMethod_InvalidType_InterfaceMethodNotImplemented@InterfaceMethodNotImplemented
extends [System.Runtime]System.Object
implements IReabstractDefaultImplementation, IInheritedDefaultImplInterface, IInterface
{
Expand Down
43 changes: 43 additions & 0 deletions src/tests/ilverify/ILTests/LocalAllocTests.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 LocalAllocTestsFriend
{
}

.assembly LocalAllocTests
{
}

.class public auto ansi beforefieldinit LocAllocTests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a positive test as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added test for stack underflow & positive test

extends [System.Runtime]System.Object
{
.method private hidebysig instance void Load.LocAllocShouldFailWhenStackNotEmpty_Invalid_Unverifiable.LocallocStackNotEmpty() cil managed
{
ldnull // pretend there's meaningfull value on stack
ldc.i4.2 // size parameter for localloc
localloc
pop // pop localloc pointer
pop // pop ldnull
ret
}

.method private hidebysig instance void Load.LocAllocShouldFailWhenSizeIsAbsent_Invalid_Unverifiable.StackUnderflow() cil managed
{
localloc
pop // pop localloc pointer
ret
}

.method private hidebysig instance void Load.LocAllocShouldSuccesWhenSizeIsPresent_Invalid_Unverifiable() cil managed
{
ldc.i4.2 // size parameter for localloc
localloc
pop // pop localloc pointer
ret
}
}
3 changes: 3 additions & 0 deletions src/tests/ilverify/ILTests/LocalAllocTests.ilproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="ILTests.targets" />
</Project>