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

Alexey Bataev via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 21 04:09:34 PST 2018


Clang does not use this parameter as it is not required. All the required initialization can be performed using only the first ctor parameter.

Best regards,
Alexey Bataev

20 дек. 2018 г., в 17:24, Simone Atzeni via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> написал(а):

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.
________________________________
<threadprivate_class_cctor.cpp>
<threadprivate_class_cctor.ll>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181221/1ccba0a2/attachment.html>


More information about the cfe-dev mailing list