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

Illegal storage access compiling call with nested ref/deref'd types #18079

Open
tersec opened this issue May 24, 2021 · 6 comments · Fixed by #20738
Open

Illegal storage access compiling call with nested ref/deref'd types #18079

tersec opened this issue May 24, 2021 · 6 comments · Fixed by #20738

Comments

@tersec
Copy link
Contributor

tersec commented May 24, 2021

Calling a function with nested layers of object construction, each of which constructs a reference object then dereferences it, results in SIGSEGV at compile time with Nim versions 1.2.12, 1.4.2, and current git head.

Example

type
  Foo = object
    discard

  Bar = object
    x: Foo

proc baz(state: var Bar) = discard
baz((ref Bar)(x: (new Foo)[])[])

Current Output

$ nim c sigsegv.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/etc/nim/config.nims' [Conf]
....SIGSEGV: Illegal storage access. (Attempt to read from nil?)
$ nim --version
Nim Compiler Version 1.4.2 [Linux: amd64]
Compiled at 2021-05-13
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release
$ ~/Nim/bin/nim c sigsegv.nim
Hint: used config file 'Nim/config/nim.cfg' [Conf]
Hint: used config file 'Nim/config/config.nims' [Conf]
....SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault
$ ~/Nim/bin/nim --version
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-05-24
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: d217888e5679aff063668930bd00892c4f5cb2b3
active boot switches: -d:release
$ ./env.sh nim c ../sigsegv.nim 
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: sigsegv [Processing]
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
$ ./env.sh nim --version
Nim Compiler Version 1.2.12 [Linux: amd64]
Compiled at 2021-05-23
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 121628357ec7fae91335bd392f03b0e6dd249319
active boot switches: -d:release

Expected Output

Not a segfault.

@bung87
Copy link
Collaborator

bung87 commented Oct 28, 2022

what's the expected behavior by language design?

@Araq
Copy link
Member

Araq commented Oct 28, 2022

Don't crash at compile-time and compile it properly.

@bung87
Copy link
Collaborator

bung87 commented Nov 1, 2022

I can make this compile but am not sure about correctness, according to below, but it seems no other way construct var Bar in this kind of form. also it's kind fine as that is semmatch error this is just cgen error.

proc(x: var X | ref X) fails to compile #4448

    The mutability aspect of a type is not lifted to an "or" type. This is not a bug, but it could be a feature that we support. I personally don't like it at all, it's only useful for confused code that uses both var and ref and cannot make up its mind.

Originally posted by @Araq in #4448 (comment)

@bung87
Copy link
Collaborator

bung87 commented Nov 7, 2022

after ecc8f61, it's still remain same error on gc refc, but compile and runs on orc

@tersec
Copy link
Contributor Author

tersec commented Nov 7, 2022

That sounds not very fixed/closed.

@bung87
Copy link
Collaborator

bung87 commented Nov 7, 2022

That sounds not very fixed/closed.

yeah, before my patch it's same error on orc, so I thought that fixed, I just re check these related 3 issues on refc, found now they turn to refc issues.

capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…ref/deref (nim-lang#20738)

* add test case
* refactoring transformAddrDeref and fix nim-lang#18079
* fix jsgen
narimiran pushed a commit that referenced this issue Apr 25, 2023
#20738)

* add test case
* refactoring transformAddrDeref and fix #18079
* fix jsgen

(cherry picked from commit ecc8f61)
narimiran pushed a commit that referenced this issue Apr 25, 2023
#20738)

* add test case
* refactoring transformAddrDeref and fix #18079
* fix jsgen

(cherry picked from commit ecc8f61)
bung87 added a commit to bung87/Nim that referenced this issue Jul 29, 2023
…ref/deref (nim-lang#20738)

* add test case
* refactoring transformAddrDeref and fix nim-lang#18079
* fix jsgen
@bung87 bung87 reopened this Aug 3, 2023
@ringabout ringabout added the refc refc issues label Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants