Before C# 7.2, the stackalloc feature could only be used in unsafe code, so it was the programmer's responsibility to ensure it is used safely. In 7.2, we are permitting it to be used in safe code (as part of the Span feature). So the compiler/language must ensure it is used in such a way that the compiler can generate correct code.
The following constraints regarding the CLI localloc instruction are not currently obeyed by the implementation in the features/readonly-ref branch:
The localloc instruction cannot occur within an exception block: filter, catch, finally, or fault.
Correct CIL required that the evaluation stack be empty, apart from the size item.
Before C# 7.2, the
stackallocfeature could only be used in unsafe code, so it was the programmer's responsibility to ensure it is used safely. In 7.2, we are permitting it to be used in safe code (as part of the Span feature). So the compiler/language must ensure it is used in such a way that the compiler can generate correct code.The following constraints regarding the CLI
locallocinstruction are not currently obeyed by the implementation in thefeatures/readonly-refbranch: