Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RVO not applied to object with large array #14470

Closed
arnetheduck opened this issue May 27, 2020 · 3 comments
Closed

RVO not applied to object with large array #14470

arnetheduck opened this issue May 27, 2020 · 3 comments

Comments

@arnetheduck
Copy link
Contributor

arnetheduck commented May 27, 2020

type X = object
  v: array[1024*1024*8, int]

proc f(): X =
  result.v[0] = 1

var x = (ref X)()
x[] = f()
echo x.v[0]

note how huge object is placed on stack, crashing the application on linux (which has an 8mb default stack size)

N_LIB_PRIVATE N_NIMCALL(tyObject_X__KqwtR1mZdQ5eNccTtsN3pA, f__KQQBzps5MRoTwkbIifdBMQ)(void) {
        tyObject_X__KqwtR1mZdQ5eNccTtsN3pA result;
...
        return result;
[arnetheduck@tempus tmp]$ nim --version
Nim Compiler Version 1.2.0 [Linux: amd64]
Compiled at 2020-04-03
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release
@mratsim
Copy link
Collaborator

mratsim commented May 27, 2020

var x = f() should be changed to

var x: ref X
new x
x[] = f()

Otherwise the caller would overflow as well.

Second, I think Nim is actually the C-array semantics there (so there is a conflict between RVO and C-arrays)

@arnetheduck
Copy link
Contributor Author

fixed example - C array sematics are not relevant - in fact, if you change to f(): array[...] it'll pass return value by pointer like it should

@Araq
Copy link
Member

Araq commented May 27, 2020

Yeah, I noticed this too after I wrote the RFC... ;-)

Araq added a commit that referenced this issue Nov 9, 2021
@Araq Araq closed this as completed in 15157d0 Nov 9, 2021
narimiran pushed a commit that referenced this issue Nov 11, 2021
(cherry picked from commit 15157d0)
narimiran pushed a commit that referenced this issue Dec 6, 2021
(cherry picked from commit 15157d0)
narimiran pushed a commit that referenced this issue Dec 6, 2021
(cherry picked from commit 15157d0)
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants