This patch fixes the issue that the globalized variable is not properly
initialized when it is a byval struct function argument.
Fixes #56218.
Differential D129008
[Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument tianshilei1992 on Jul 1 2022, 10:39 AM. Authored by
Details
Diff Detail
Event TimelineComment Actions No we don't. I think the best place to emit copy is where the globalized variable is generated.
Comment Actions Is it for ObjC? Looking at the comments, it looks like it's for C: // These functions emit calls to the special functions of non-trivial C // structs.
Comment Actions That's not ObjC. It can be C or C++. My apology I should have added more context here. In OpenMP, we need to "globalize" certain captured local variables by allocating another buffers and then copy the memory. If the local variables are structs or even C++ classes, the copy has to be done by invoking the corresponding copy constructors. However, I don't know how to invoke the copy constructor here. callCStructCopyConstructor only does plain copy. It's not gonna work for C++ classes. Comment Actions You need to do it manually. Usually we built the required copy constructor call in Sema (it requires correct lookup) and then emitted it in codegen. Comment Actions Right. If we really needed the constructor call, we emitted special helper expressions/statements and stored them in the associated construct/clause, and then emitted it, if required. Comment Actions Right. C structs can require more than just memcpy to copy in several different situations (all involving language extensions), but it doesn't require Sema to be involved: it doesn't introduce uses of user declarations, and the compiler can figure out the work it needs to do with a straightforward recursive inspection of the field types, so IRGen just synthesizes those operations automatically when requested. Neither condition holds in C++, so Sema has to synthesize a copy expression which resolves the correct copy constructor and sets up any extra arguments it might require, triggering appropriate diagnostics and/or tracking of used decls. There are a bunch of places we do that for various language extensions already, including a bunch in the OpenMP code, and we usually just store the expression in the associated AST node. Comment Actions @rjmccall @ABataev Thanks for the help. So the basic idea is to build the expressions in Sema for those captured decls and then emit them accordingly in code gen, right?
Could you please point me a rough location where we already have similar things such that I can learn and do the same thing for globalization? Thanks. Comment Actions Yes.
You can check ActOnOpenMPFirstprivateClause, lines 18322-18353 (building of VDInitRefExpr) |
Hi @aaron.ballman, is it possible to invoke the copy constructor of a struct/class here, either it is user defined or default one?