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

sizeof array with static N crash in type section #12636

Closed
mratsim opened this issue Nov 10, 2019 · 0 comments · Fixed by #15850
Closed

sizeof array with static N crash in type section #12636

mratsim opened this issue Nov 10, 2019 · 0 comments · Fixed by #15850

Comments

@mratsim
Copy link
Collaborator

mratsim commented Nov 10, 2019

The following crashes in a type section, removing sizeof(array[N, ptr T]) avoids the crash.

const CacheLineSize = 128

type Foo = object
  x: int

static:
  echo(CacheLineSize - sizeof(array[10, ptr Foo]) - sizeof(int) - sizeof(pointer))
  echo "Successful static compute"

type
  Stack*[N: static int, T: object] = object
    pad: array[CacheLineSize - sizeof(array[N, ptr T]) - sizeof(int) - sizeof(pointer), byte]
    stack: array[N, ptr T]
    len*: int
    rawMem: ptr array[N, T]

echo "Hello world"

The error message points to int128

32
Successful static compute
fatal.nim(39)            sysFatal
Error: unhandled exception: int128.nim(330, 11) `false` overflow [AssertionError]

Replacing N by 10 works so static is important.

Workaround: use N * sizeof(ptr T) instead of sizeof(array[N, ptr T])

cooldome added a commit that referenced this issue Nov 5, 2020
@cooldome cooldome mentioned this issue Nov 5, 2020
Araq pushed a commit that referenced this issue Nov 5, 2020
* close #11142

* fix #12636

* undo unwanted changes

* fix illegal recursion case
narimiran pushed a commit that referenced this issue Nov 9, 2020
* close #11142

* fix #12636

* undo unwanted changes

* fix illegal recursion case

(cherry picked from commit 3af7818)
PMunch pushed a commit to PMunch/Nim that referenced this issue Jan 6, 2021
* close nim-lang#11142

* fix nim-lang#12636

* undo unwanted changes

* fix illegal recursion case
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
* close nim-lang#11142

* fix nim-lang#12636

* undo unwanted changes

* fix illegal recursion case
irdassis pushed a commit to irdassis/Nim that referenced this issue Mar 16, 2021
* close nim-lang#11142

* fix nim-lang#12636

* undo unwanted changes

* fix illegal recursion case
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
* close nim-lang#11142

* fix nim-lang#12636

* undo unwanted changes

* fix illegal recursion case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant