mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
A constant-size stackalloc initializer whose buffer is only passed to a static call (never dereferenced as a typed pointer) threw "given Block is invalid!". TranslateStackAllocInitializer recovers the element type from the surrounding type hint, but that hint is unreliable for this shape: the constant allocation size is folded to a byte count, so it can no longer be read off a 'count * sizeof(T)' expression, and the buffer is kept on the stack as a native int instead of a T* local, leaving the hint a non-pointer. The guard only repaired an incompatible pointer hint, so a non-pointer hint fell through to a 'byte' element type that is incompatible with the actual stores, and the per-element check threw. Derive the element type from the type being stored whenever the hint is not already a compatible pointer. The regression is driven by the code shape, not the compiler version: in optimized builds the buffer is kept on the stack as a native int whenever it is passed to a static call without being dereferenced. This reproduces across Roslyn versions, including the pinned test compiler, so the added fixture is red without this fix in the optimized configurations. Assisted-by: Claude:claude-opus-4-8:Claude Codepull/3813/head
2 changed files with 23 additions and 1 deletions
Loading…
Reference in new issue