Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Fix Array.Reverse incorrectly validating index - #1297

Merged
jkotas merged 1 commit into
dotnet:masterfrom
hughbe:array-reverse-lb
May 18, 2016
Merged

jkotas merged 1 commit into
dotnet:masterfrom
hughbe:array-reverse-lb

Conversation

@hughbe

@hughbe hughbe commented May 18, 2016

Copy link
Copy Markdown
Contributor

We need to actually check GetLowerBound

This could be a breaking change, but very unlikely as mscorlib validates the index correctly.

/cc @jamesqo @jkotas

We need to actually check GetLowerBound
@MichalStrehovsky

Copy link
Copy Markdown
Member

I'll let Jan review this, but .NET Native doesn't have a real support for non-zero lower bounds. We have code that pretends to handle them here and there, but you can't actually create an array like that (it will throw).

We can try to fix these, but without regression tests (which can't be written because you can't create them), we still don't know if this works as expected. In a way you can look at the 0 lower bound assumption as a perf optimization.

@jkotas

jkotas commented May 18, 2016 •

Copy link
Copy Markdown
Member

I agree. There are number of places where the calls to GetLowerBound were stripped. I does not make sense to add them ad-hoc. If we were to add support for non-zero lower bound back, we would need to do a pass to add it back everywhere.

@hughbe

hughbe commented May 18, 2016

Copy link
Copy Markdown
Contributor Author

Sure - should I close this then? It seems to not make much sense why some methods check for the lower bounds and others dont

@MichalStrehovsky

Copy link
Copy Markdown
Member

It seems to not make much sense why some methods check for the lower bounds and others don't.

Agreed. We might want to make a call here:

  • Cut a workitem to make a pass over the code and hardcode the assumption of 0 lower bounds everywhere (it's a perf optimization, although rather insignificant - mostly it cleans up the codebase).
  • Keep the checks there, in case we decide to support non-zero lower bounds on .NET Native later (in which case we could even merge this because it doesn't really change things when we look at the big picture)

@jkotas

jkotas commented May 18, 2016

Copy link
Copy Markdown
Member

The perf optimization can be still done even with GetLowerBound(0) calls in the code if we cared - the GetLowerBound(0) just needs to be written as inlineable.

I think it is goodness to make the code same as CoreCLR - which this change does.

@jkotas
jkotas merged commit ae7b871 into dotnet:master May 18, 2016
@jkotas

jkotas commented May 18, 2016

Copy link
Copy Markdown
Member

Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants