dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.42k stars 199 forks source link

[NativeAOT-LLVM] Fix array allocators #2342

Closed SingleAccretion closed 1 year ago

SingleAccretion commented 1 year ago

There were two bugs: 1) The overflow detection wasn't working properly due to C++ rules. The "align up" arithmetic was being performed in 32 bit integers. 2) When we overflow on 32 bit, we are supposed to OOM, not actually throw an overflow exception.

Fix both issues by simply delegating to the slow path helpers when we have large (65K+ elements) arrays.

With this fix, a small libraries test suite runs to completion on my machine:

Finished:    System.Collections.Specialized.Tests

=== TEST EXECUTION SUMMARY ===
Total: 2132, Errors: 0, Failed: 0, Skipped: 8, Time: 24.0773544s
SingleAccretion commented 1 year ago

@dotnet/nativeaot-llvm

jkotas commented 1 year ago

It would be nice to upstream these changes to https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/Runtime/portable.cpp