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

Calling a var-param-proc results in gcc error #18080

Closed
tersec opened this issue May 24, 2021 · 1 comment · Fixed by #24335
Closed

Calling a var-param-proc results in gcc error #18080

tersec opened this issue May 24, 2021 · 1 comment · Fixed by #24335
Assignees
Labels
refc refc issues Severe

Comments

@tersec
Copy link
Contributor

tersec commented May 24, 2021

Calling a var-param'd proc with a certain object construction results in a gcc error.

Example

type
  Foo = object
    discard

  Bar = object
    x: Foo

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

Current Output

$ gcc --version
gcc (Debian 10.2.1-6) 10.2.1 20210110
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/etc/nim/config.nims' [Conf]
....CC: initializer_element_is_not_constant.nim
/home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c:54:87: error: initializer element is not constant
   54 | static NIM_CONST tyObject_Bar__GgKelZxvGOIwRl5q7fQcEA* TM__ErwDwTejKczskj5eQoYo4w_2 = TM__ErwDwTejKczskj5eQoYo4w_2;
      |                                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/usr/lib/nim -I/home/outhquin -o /home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c.o /home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c' failed with exit code: 1
$ 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 initializer_element_is_not_constant.nim
Hint: used config file '/home/outhquin/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/outhquin/Nim/config/config.nims' [Conf]
....
CC: stdlib_assertions.nim
CC: stdlib_system.nim
CC: initializer_element_is_not_constant.nim
/home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c:42:87: error: initializer element is not constant
   42 | static NIM_CONST tyObject_Bar__GgKelZxvGOIwRl5q7fQcEA* TM__ErwDwTejKczskj5eQoYo4w_2 = TM__ErwDwTejKczskj5eQoYo4w_2;
      |                                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/outhquin/Nim/lib -I/home/outhquin -o /home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c.o /home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c' failed with exit code: 1
$ ~/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 ../initializer_element_is_not_constant.nim
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: initializer_element_is_not_constant [Processing]
CC: stdlib_system.nim
CC: initializer_element_is_not_constant.nim
/home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c:44:87: error: initializer element is not constant
   44 | static NIM_CONST tyObject_Bar__GgKelZxvGOIwRl5q7fQcEA* TM__ErwDwTejKczskj5eQoYo4w_2 = TM__ErwDwTejKczskj5eQoYo4w_2;
      |                                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: execution of an external compiler program 'gcc -c  -w   -I/home/outhquin/nimbus-eth2/vendor/nimbus-build-system/vendor/Nim/lib -I/home/outhquin -o /home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c.o /home/outhquin/.cache/nim/initializer_element_is_not_constant_d/@minitializer_element_is_not_constant.nim.c' failed with exit code: 1
$ ./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 gcc error.

Additional Information

Issue #18079 is related, but different, because it constructs the Foo-type object differently and results in a SIGSEGV rather than a gcc error.

@tersec tersec changed the title Calling a var-param-proc with Calling a var-param-proc results in gcc error May 24, 2021
@Araq Araq added the Severe label May 31, 2021
@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

@ringabout ringabout added the refc refc issues label Apr 4, 2023
@ringabout ringabout self-assigned this Oct 22, 2024
@Araq Araq closed this as completed in aa90d00 Oct 25, 2024
narimiran pushed a commit that referenced this issue Dec 20, 2024
…24335)

fixes #18081;
fixes #18080
fixes #18079

reverts #20738

It is probably more reasonable to use the type node from `nkObjConstr`
since it is barely changed unlike the external type, which is
susceptible to code transformation e.g. `addr(deref objconstr)`.

(cherry picked from commit aa90d00)
narimiran pushed a commit that referenced this issue Jan 14, 2025
…24335)

fixes #18081;
fixes #18080
fixes #18079

reverts #20738

It is probably more reasonable to use the type node from `nkObjConstr`
since it is barely changed unlike the external type, which is
susceptible to code transformation e.g. `addr(deref objconstr)`.

(cherry picked from commit aa90d00)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment