In LocalVarSig syntax diagram the CustomMod and Constraint elements are in a loop, so this means there can be multiple Constraint elements. If there are more than one Constraint element, what is its semantics? Thanks!
From ECMA-335 §II.23.2.9, emphasis added:
The Constraint item in Signatures currently has only one possible value, ELEMENT_TYPE_PINNED (§II.23.1.16), which specifies that the target type is pinned in the runtime heap, and will not be moved by the actions of garbage collection.
A Constraint can only be applied within a LocalVarSig (not a FieldSig).
So pinned
is the only possible constraint value, at least in the current version of CIL.
So, are multiple instances of pinned
valid? It appears so. The assembler (ILasm) accepts multiple instances for a local variable:
.locals init (int32& pinned pinned pinned x)
If I assemble this and then disassemble it (ILdasm), the resulting IL retains the repeated pinned
keyword. Peering into the assembly with MdDumper also shows the repeated 0x45
byte in the StandAloneSig
table.
I haven't seen any verification differences with multiple pinned
constraints, so I assume they are redundant, and equivalent to just having one pinned
.