[cfe-dev] How to make clang call `__kmpc_threadprivate_register` with a not NULL copy constructor

Simone Atzeni via cfe-dev cfe-dev at lists.llvm.org
Thu Dec 20 14:24:31 PST 2018


Hi guys,

I am having some trouble making clang++ generate a call to `__kmpc_threadprivate_register` where the copy constructor is not NULL.
Looking at the generated LLVM IR it seems that clang approach, not matter how an object (declared as OpenMP threadprivate) is initialized, it will always generate a `__kmpc_global_ctor` and pass that to the ctor arg of ` __kmpc_threadprivate_register`.
The `__kmpc_global_ctor` will then do the object initialization in whatever way is specified by the program.

For example, in the C++ program attached, we have an object `x` of class `myclass` initialized with another object `a` of type `myclass`, so the copy constructor of `myclass` will be called to initialize the instance of x.
Then x is declared as `omp threadprivate`.

In the LLVM IR (also attached, I put only the interesting LLVM IR) there is a `__kmpc_global_ctor_` which calls inside the copy constructor. The `__kmpc_global_ctor_` is passed to the kmpc function `__kmpc_threadprivate_register` as ctor arg, while NULL is passed in the cctor arg position.

My question is, is this an implementation choice or there is actually a way to make clang pass a copy constructor as a argument to `__kmpc_threadprivate_register`?

Maybe I am writing the wrong example and I am missing some knowledge about how C++ OpenMP threadprivate is supposed to work.

Thank you!
Simone


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181220/51d5f1b5/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: threadprivate_class_cctor.cpp
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181220/51d5f1b5/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: threadprivate_class_cctor.ll
Type: application/octet-stream
Size: 1349 bytes
Desc: threadprivate_class_cctor.ll
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181220/51d5f1b5/attachment.obj>


More information about the cfe-dev mailing list