Linker doesn't trim unused locals when the only usage is in `initobj`
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
Related to https://github.com/mono/linker/issues/1805.
If you have code such as:
```csharp
Unsafe.SkipInit(out Vector128 value);
if (Sse.IsSupported)
{
value = Vector128.Create(value);
}
```
The linker will trim out the initialization but not the `Unsafe.SkipInit(out Vector128 value);` as it doesn't recognize the call today.
If you try to refactor this to something such as:
```csharp
Vector128 value;
if (Sse.IsSupported)
{
value = Vector128.Create(value);
}
else
{
value = default;
}
```
The linker trims it down to just: `Vector128 value = default;` but does not remove the local and therefore does not remove the now unused `Vector128` type even though the only usage of `value` is in an `initobj valuetype [System.Private.CoreLib]System.Runtime.Intrinsics.Vector128`1` instruction.
The linker should likely recognize this scenario and trim the unused local.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.