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

invalid C++ codegen in --mm:refc with Thread/Atomic/createThread (no ptr involved) #24160

Open
tersec opened this issue Sep 23, 2024 · 1 comment

Comments

@tersec
Copy link
Contributor

tersec commented Sep 23, 2024

Description

import std/atomics
type N = object
  u: Atomic[int]
proc w(args: N) = discard
var e: Thread[N]
createThread(e, w, default(N))

Use nim cpp --mm:refc m.nim

Nim Version

v2.0.8:

Nim Compiler Version 2.0.8 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf
active boot switches: -d:release

version-2-0:

Nim Compiler Version 2.0.9 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 27381cc60213e19aa34664176bd358ca5e45bd5a
active boot switches: -d:release

version-2-2:

Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 755307be61e4ee7b32c8354b2c303d04bdfc3a3e
active boot switches: -d:release

devel:

Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: a55c15c651b805c5eca4475f9845a57adf6cddef
active boot switches: -d:release
g++ (Debian 14.2.0-5) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.

Current Output

Hint: used config file '/tmp/nim/config/nim.cfg' [Conf]
Hint: used config file '/tmp/nim/config/config.nims' [Conf]
.........................................................................
CC: nim/lib/system/exceptions.nim
CC: nim/lib/std/private/threadtypes.nim
CC: nim/lib/std/private/digitsutils.nim
CC: nim/lib/std/assertions.nim
CC: nim/lib/system/dollars.nim
CC: nim/lib/std/typedthreads.nim
CC: nim/lib/pure/collections/sharedlist.nim
CC: nim/lib/system.nim
CC: m.nim
/tmp/nimcache/@mm.nim.cpp: In function ‘void NimMainModule()’:
/tmp/nimcache/@mm.nim.cpp:177:60: error: use of deleted function ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::tyObject_N__QM8RoNEnl77SyM0iU3IJ8A(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’
  177 |         nimlf_(6, "/tmp/m.nim");        createThread__m_u27((*(&e__m_u15)), w__m_u6, T1_);
      |                                         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mm.nim.cpp:40:8: note: ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::tyObject_N__QM8RoNEnl77SyM0iU3IJ8A(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’ is implicitly deleted because the default definition would be ill-formed:
   40 | struct tyObject_N__QM8RoNEnl77SyM0iU3IJ8A {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mm.nim.cpp: At global scope:
/tmp/nimcache/@mm.nim.cpp:40:8: error: use of deleted function ‘std::atomic<long int>::atomic(const std::atomic<long int>&)’
In file included from /tmp/nimcache/@mm.nim.cpp:9:
/usr/include/c++/14/atomic:880:7: note: declared here
  880 |       atomic(const atomic&) = delete;
      |       ^~~~~~
/tmp/nimcache/@mm.nim.cpp:40:8: note: use ‘-fdiagnostics-all-candidates’ to display considered candidates
   40 | struct tyObject_N__QM8RoNEnl77SyM0iU3IJ8A {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mm.nim.cpp: In function ‘void NimMainModule()’:
/tmp/nimcache/@mm.nim.cpp:177:60: note: use ‘-fdiagnostics-all-candidates’ to display considered candidates
  177 |         nimlf_(6, "/tmp/m.nim");        createThread__m_u27((*(&e__m_u15)), w__m_u6, T1_);
      |                                         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mm.nim.cpp:73:174: note:   initializing argument 3 of ‘void createThread__m_u27(tyObject_Thread__nZr9anuXgjZYbdDHt5WUT9ag&, tyProc__wfITwjpjmvZY7CvJJ4a1Qw, tyObject_N__QM8RoNEnl77SyM0iU3IJ8A)’
   73 | N_LIB_PRIVATE N_NIMCALL(void, createThread__m_u27)(tyObject_Thread__nZr9anuXgjZYbdDHt5WUT9ag& t_p0, tyProc__wfITwjpjmvZY7CvJJ4a1Qw tp_p1, tyObject_N__QM8RoNEnl77SyM0iU3IJ8A param_p2);
      |                                                                                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:144,
                 from /tmp/nimcache/@mm.nim.cpp:8:
/tmp/nimcache/@mm.nim.cpp: In function ‘void atmmdotnim_DatInit000()’:
/tmp/nimcache/@mm.nim.cpp:196:81: error: ‘TY__P0dQMTG1GttfzBfnDUwPsg’ {aka ‘struct std::atomic<long int>’} has no member named ‘raw’
  196 | TM__oKjqU9aPjLw9bdxdDjEzAT5Q_0[1].offset = offsetof(TY__P0dQMTG1GttfzBfnDUwPsg, raw);
      |                                                                                 ^~~
Error: execution of an external compiler program 'g++ -c -std=gnu++17 -funsigned-char  -w -fmax-errors=3 -fpermissive -pthread   -I/tmp/nim/lib -I/tmp -o /tmp/nimcache/@mm.nim.cpp.o /tmp/nimcache/@mm.nim.cpp' failed with exit code: 1


/tmp/nimcache/@mnim@slib@[email protected]: In function ‘void createThread__m_u27(tyObject_Thread__nZr9anuXgjZYbdDHt5WUT9ag&, tyProc__wfITwjpjmvZY7CvJJ4a1Qw, tyObject_N__QM8RoNEnl77SyM0iU3IJ8A)’:
/tmp/nimcache/@mnim@slib@[email protected]:378:21: error: use of deleted function ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A& tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::operator=(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’
  378 |         t_p0.data = param_p2;
      |                     ^~~~~~~~
/tmp/nimcache/@mnim@slib@[email protected]:70:8: note: ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A& tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::operator=(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’ is implicitly deleted because the default definition would be ill-formed:
   70 | struct tyObject_N__QM8RoNEnl77SyM0iU3IJ8A {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mnim@slib@[email protected]: At global scope:
/tmp/nimcache/@mnim@slib@[email protected]:70:8: error: use of deleted function ‘std::atomic<long int>& std::atomic<long int>::operator=(const std::atomic<long int>&)’
In file included from /tmp/nimcache/@mnim@slib@[email protected]:8:
/usr/include/c++/14/atomic:881:15: note: declared here
  881 |       atomic& operator=(const atomic&) = delete;
      |               ^~~~~~~~
/tmp/nimcache/@mnim@slib@[email protected]:70:8: note: use ‘-fdiagnostics-all-candidates’ to display considered candidates
   70 | struct tyObject_N__QM8RoNEnl77SyM0iU3IJ8A {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mnim@slib@[email protected]: In function ‘void createThread__m_u27(tyObject_Thread__nZr9anuXgjZYbdDHt5WUT9ag&, tyProc__wfITwjpjmvZY7CvJJ4a1Qw, tyObject_N__QM8RoNEnl77SyM0iU3IJ8A)’:
/tmp/nimcache/@mnim@slib@[email protected]:378:21: note: use ‘-fdiagnostics-all-candidates’ to display considered candidates
  378 |         t_p0.data = param_p2;
      |                     ^~~~~~~~
/tmp/nimcache/@mnim@[email protected]: In function ‘void threadProcWrapDispatch__m_u65(tyObject_Thread__nZr9anuXgjZYbdDHt5WUT9ag*)’:
/tmp/nimcache/@mnim@[email protected]:5729:50: error: use of deleted function ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A& tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::operator=(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’
 5729 |                                 T4_ = (*thrd_p0).data;
      |                                                  ^~~~
/tmp/nimcache/@mnim@[email protected]:334:8: note: ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A& tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::operator=(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’ is implicitly deleted because the default definition would be ill-formed:
  334 | struct tyObject_N__QM8RoNEnl77SyM0iU3IJ8A {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mnim@[email protected]: At global scope:
/tmp/nimcache/@mnim@[email protected]:334:8: error: use of deleted function ‘std::atomic<long int>& std::atomic<long int>::operator=(const std::atomic<long int>&)’
In file included from /tmp/nimcache/@mnim@[email protected]:18:
/usr/include/c++/14/atomic:881:15: note: declared here
  881 |       atomic& operator=(const atomic&) = delete;
      |               ^~~~~~~~
/tmp/nimcache/@mnim@[email protected]:334:8: note: use ‘-fdiagnostics-all-candidates’ to display considered candidates
  334 | struct tyObject_N__QM8RoNEnl77SyM0iU3IJ8A {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nimcache/@mnim@[email protected]: In function ‘void threadProcWrapDispatch__m_u65(tyObject_Thread__nZr9anuXgjZYbdDHt5WUT9ag*)’:
/tmp/nimcache/@mnim@[email protected]:5729:50: note: use ‘-fdiagnostics-all-candidates’ to display considered candidates
 5729 |                                 T4_ = (*thrd_p0).data;
      |                                                  ^~~~
/tmp/nimcache/@mnim@[email protected]:5731:35: error: use of deleted function ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::tyObject_N__QM8RoNEnl77SyM0iU3IJ8A(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’
 5731 |                 (*thrd_p0).dataFn(x);
      |                                   ^
/tmp/nimcache/@mnim@[email protected]:334:8: note: ‘tyObject_N__QM8RoNEnl77SyM0iU3IJ8A::tyObject_N__QM8RoNEnl77SyM0iU3IJ8A(const tyObject_N__QM8RoNEnl77SyM0iU3IJ8A&)’ is implicitly deleted because the default definition would be ill-formed:
  334 | struct tyObject_N__QM8RoNEnl77SyM0iU3IJ8A {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated due to -fmax-errors=3.

Expected Output

No invalid C++ codegen

Known Workarounds

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Sep 23, 2024

Doesn't work with --mm:orc either, createThread tries to copy the param to the thread data.

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