Skip to content

[NativeAOT-LLVM] Fix array allocators - #2342

Merged
jkotas merged 2 commits into
dotnet:feature/NativeAOT-LLVMfrom
SingleAccretion:Arr-Alloc
Jul 18, 2023
Merged

jkotas merged 2 commits into
dotnet:feature/NativeAOT-LLVMfrom
SingleAccretion:Arr-Alloc

Conversation

@SingleAccretion

@SingleAccretion SingleAccretion commented Jul 15, 2023 •

Copy link
Copy Markdown

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

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.
@jkotas jkotas added the area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) label Jul 16, 2023
@SingleAccretion
SingleAccretion marked this pull request as ready for review July 16, 2023 09:59
@SingleAccretion

Copy link
Copy Markdown
Author

@dotnet/nativeaot-llvm

Actually, I question the correctness of this code as well, but let's leave it be for now.

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jkotas

jkotas commented Jul 18, 2023

Copy link
Copy Markdown
Member

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

@jkotas
jkotas merged commit f26c617 into dotnet:feature/NativeAOT-LLVM Jul 18, 2023
Comment on lines 252 to 255
if (paddedSize > SIZE_MAX - 12)
{
ASSERT_UNCONDITIONALLY("NYI"); // TODO: Throw overflow
ThrowOverflowException(pShadowStack, pArrayEEType);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is dead code now that the large element sizes are handled as early out above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants