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
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@
ret
}

.method static public hidebysig void Branch.BackwardWithoutPredecessor_Invalid_BackwardBranch() cil managed
.method static public hidebysig void Branch.BackwardWithoutPredecessor_Invalid_BackwardBranch_Validation_Valid() cil managed
{
br MethodEnd

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/ILVerification.Tests/ILTests/CallTests.il
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
ret
}

.method public hidebysig instance void Call.BaseMethodModThisLdarga_Invalid_ThisMismatch() cil managed
.method public hidebysig instance void Call.BaseMethodModThisLdarga_Invalid_ThisMismatch_Validation_Valid() cil managed
{
ldarg.0
call instance void SimpleClass::VirtualMethod()
Expand All @@ -63,7 +63,7 @@
ret
}

.method public hidebysig instance void Call.BaseMethodModThisStarg_Invalid_ThisMismatch() cil managed
.method public hidebysig instance void Call.BaseMethodModThisStarg_Invalid_ThisMismatch_Validation_Valid() cil managed
{
ldarg.0
call instance void SimpleClass::VirtualMethod()
Expand Down Expand Up @@ -128,7 +128,7 @@
ret
}

.method public hidebysig instance void Call.ExternBaseMethod_Invalid_ThisMismatch(class DerivedClass c) cil managed
.method public hidebysig instance void Call.ExternBaseMethod_Invalid_ThisMismatch_Validation_Valid(class DerivedClass c) cil managed
{
ldarg.1
call instance void SimpleClass::VirtualMethod()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@
ret
}

.method public static void Filter.ExceptionLeftOnStack_Invalid_EndfilterStack() cil managed
.method public static void Filter.ExceptionLeftOnStack_Invalid_EndfilterStack_Validation_Valid() cil managed
{
.maxstack 2

Expand Down
31 changes: 31 additions & 0 deletions src/coreclr/tools/ILVerification.Tests/ILTests/InitLocalsTests.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 InitLocalsTests
{
}

// localsinit is required only for verifiable methods (III.1.8.1.1)
.class public auto ansi beforefieldinit InitLocalsTestsType
extends [System.Runtime]System.Object
{
.method public hidebysig static void InitLocals.LoadLocal_Invalid_InitLocals_Validation_Valid() cil managed
{
.locals (int32 V_0)
ldloc.0
pop
ret
}

.method public hidebysig static void InitLocals.LoadLocalAddress_Invalid_InitLocals_Validation_Valid() cil managed
{
.locals (int32 V_0)
ldloca.s V_0
pop
ret
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(MSBuildProjectName).il" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions src/coreclr/tools/ILVerification.Tests/ILTests/PrefixTests.il
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
ret
}

.method static public hidebysig void ConstrainedCall.UnconstrainedTypeParam_Invalid_ConstrainedTypeNoInterfaceImpl<T>() cil managed
.method static public hidebysig void ConstrainedCall.UnconstrainedTypeParam_Invalid_ConstrainedTypeNoInterfaceImpl_Validation_Valid<T>() cil managed
{
constrained. !!T
call void IStaticInterface::StaticAbstractMethod()
ret
}

.method static public hidebysig void ConstrainedCall.NonImplStruct_Invalid_ConstrainedTypeNoInterfaceImpl() cil managed
.method static public hidebysig void ConstrainedCall.NonImplStruct_Invalid_ConstrainedTypeNoInterfaceImpl_Validation_Valid() cil managed
{
constrained. NonImplStruct
call void IStaticInterface::StaticAbstractMethod()
Expand Down Expand Up @@ -101,15 +101,15 @@
ret
}

.method static public hidebysig void ConstrainedLdftn.UnconstrainedTypeParam_Invalid_ConstrainedTypeNoInterfaceImpl<T>() cil managed
.method static public hidebysig void ConstrainedLdftn.UnconstrainedTypeParam_Invalid_ConstrainedTypeNoInterfaceImpl_Validation_Valid<T>() cil managed
{
constrained. !!T
ldftn void IStaticInterface::StaticAbstractMethod()
pop
ret
}

.method static public hidebysig void ConstrainedLdftn.NonImplStruct_Invalid_ConstrainedTypeNoInterfaceImpl() cil managed
.method static public hidebysig void ConstrainedLdftn.NonImplStruct_Invalid_ConstrainedTypeNoInterfaceImpl_Validation_Valid() cil managed
{
constrained. NonImplStruct
ldftn void IStaticInterface::StaticAbstractMethod()
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/tools/ILVerification.Tests/ILTests/ReturnTests.il
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
ret
}

.method public hidebysig instance int32& Return.LocalArgByRef_Invalid_ReturnPtrToStack(int32 i) cil managed
.method public hidebysig instance int32& Return.LocalArgByRef_Invalid_ReturnPtrToStack_Validation_Valid(int32 i) cil managed
{
ldarga.s i
ret
Expand All @@ -133,7 +133,7 @@
ret
}

.method public hidebysig instance int32& Return.LocalStructFieldByRef_Invalid_ReturnPtrToStack(valuetype Struct s) cil managed
.method public hidebysig instance int32& Return.LocalStructFieldByRef_Invalid_ReturnPtrToStack_Validation_Valid(valuetype Struct s) cil managed
{
ldarg.1
ldflda int32 Struct::instanceField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
}

// The address in a typed reference can point to a local of a caller.
.method public hidebysig static int32& Refanyval.ReturnAddress_Invalid_ReturnPtrToStack(typedref tr) cil managed
.method public hidebysig static int32& Refanyval.ReturnAddress_Invalid_ReturnPtrToStack_Validation_Valid(typedref tr) cil managed
{
ldarg.0
refanyval [System.Runtime]System.Int32
Expand Down
34 changes: 26 additions & 8 deletions src/coreclr/tools/ILVerification/ILImporter.Verify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,20 @@ void Unverifiable(VerifierError error)
Invalid(error);
}

void Unverifiable(VerifierError error, object found, object expected)
{
if (!ValidationOnly)
Invalid(error, found, expected);
}

// Check for a rule that only verifiable IL must follow.
bool CheckVerifiable(bool cond, VerifierError error)
{
if (!cond && !ValidationOnly)
Invalid(error);
return cond;
}

void CheckIsNumeric(StackValue value)
{
if (!Check(StackValueKind.Int32 <= value.Kind && value.Kind <= StackValueKind.Float,
Expand Down Expand Up @@ -1431,7 +1445,8 @@ void StartImportingBasicBlock(BasicBlock basicBlock)
// ECMA III 1.7.5 Backward Branch Constraints
// if stack is not empty at beginning of this block,
// there must exist a predecessor block with lower IL offset.
Check(basicBlock.HasPredecessorWithLowerOffset, VerifierError.BackwardBranch);
// The ECMA-335 augments delete this rule, so it is no longer a validity rule.
CheckVerifiable(basicBlock.HasPredecessorWithLowerOffset, VerifierError.BackwardBranch);
}

// Copy stack state
Expand Down Expand Up @@ -1486,7 +1501,7 @@ void ImportLoadVar(int index, bool argument)
var varType = GetVarType(index, argument);

if (!argument)
Check(_initLocals, VerifierError.InitLocals);
CheckVerifiable(_initLocals, VerifierError.InitLocals);

CheckIsNotPointer(varType);

Expand Down Expand Up @@ -1517,7 +1532,7 @@ void ImportAddressOfVar(int index, bool argument)
var varType = GetVarType(index, argument);

if (!argument)
Check(_initLocals, VerifierError.InitLocals);
CheckVerifiable(_initLocals, VerifierError.InitLocals);

Check(!varType.IsByRef, VerifierError.ByrefOfByref);

Expand Down Expand Up @@ -1594,8 +1609,9 @@ void ImportCall(ILOpcode opcode, int token)
constrained = _constrained;

// The constrained type must implement the interface declaring the static virtual method
// (a Verifiability rule of the augmented III.2.1).
if (!constrained.CanCastTo(method.OwningType))
Invalid(VerifierError.ConstrainedTypeNoInterfaceImpl, constrained, method.OwningType);
Unverifiable(VerifierError.ConstrainedTypeNoInterfaceImpl, constrained, method.OwningType);
}
}

Expand Down Expand Up @@ -1753,7 +1769,7 @@ void ImportCall(ILOpcode opcode, int token)
{
var methodTypeDef = methodType.GetTypeDefinition() as MetadataType; // Method is always considered final if owning type is sealed
if (methodTypeDef == null || !methodTypeDef.IsSealed)
Check(actualThis.IsThisPtr && !_modifiesThisPtr, VerifierError.ThisMismatch);
CheckVerifiable(actualThis.IsThisPtr && !_modifiesThisPtr, VerifierError.ThisMismatch);
}
}

Expand Down Expand Up @@ -1912,7 +1928,7 @@ void ImportLdFtn(int token, ILOpcode opCode)
{
ClearPendingPrefix(Prefix.Constrained);
if (!_constrained.CanCastTo(method.OwningType))
Invalid(VerifierError.ConstrainedTypeNoInterfaceImpl, _constrained, method.OwningType);
Unverifiable(VerifierError.ConstrainedTypeNoInterfaceImpl, _constrained, method.OwningType);
}
else
{
Expand Down Expand Up @@ -2016,7 +2032,8 @@ void ImportReturn()
var actualReturnType = Pop();
CheckIsAssignable(actualReturnType, StackValue.CreateFromType(expectedReturnType));

Check((!expectedReturnType.IsByRef && !expectedReturnType.IsByRefLike) || actualReturnType.IsPermanentHome, VerifierError.ReturnPtrToStack);
// The lifetime of a returned byref is checked for verification only (III.1.8.1.2.1).
CheckVerifiable((!expectedReturnType.IsByRef && !expectedReturnType.IsByRefLike) || actualReturnType.IsPermanentHome, VerifierError.ReturnPtrToStack);
}
}
}
Expand Down Expand Up @@ -2795,7 +2812,8 @@ void ImportEndFilter()

var result = Pop(allowUninitThis: true);
Check(result.Kind == StackValueKind.Int32, VerifierError.StackUnexpected, result);
Check(_stackTop == 0, VerifierError.EndfilterStack);
// Only the Verifiability paragraph of III.3.34 requires the value to be the only item.
CheckVerifiable(_stackTop == 0, VerifierError.EndfilterStack);
}

void ImportCpBlk()
Expand Down
Loading