[cfe-dev] Where is default constructor delete function in clang?
Richard Smith via cfe-dev
cfe-dev at lists.llvm.org
Tue Mar 24 15:54:38 PDT 2020
On Mon, 23 Mar 2020 at 19:45, Yuseok Jeon via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> Dear all,
>
> I checked that clang deletes (checked IR code) structure's constructor
> when a structure is declared with a structure pointer (e.g., structure
> "Item" in the below example code).
>
> On the other hand, clang did not delete constructor when structure
> declared with variable (not a pointer) as structure "Item2" in the below
> example code.
>
> *[Example Code]*
> class DataSet
> {
> public:
> struct Item
> {
> int info;
> Item() {};
> }* theitem;
>
> struct Item2
> {
> int info;
> Item2() {};
> } theitem2;
>
> int themax;
> };
>
> int main() {
> DataSet T;
> return 0;
> }
>
> I can understand this clang's behavior (for optimization).
> However, for research purposes, I need to keep constructor although
> structure declared with a structure pointer.
>
> If you don't mind, could you please advise how I find this optimization
> function (remove constructor) in clang (I plan to update this code)?
>
Your description doesn't match what's happening. The constructor isn't
being deleted / removed from the IR. Instead, what's happening is that it's
never emitted in the first place.
The process Clang follows is:
1) Parse and semantically analyze the source file, forming an AST.
2) Emit all the strong external symbols defined in the AST, and recursively
emit any discardable symbols referenced by those strong external symbols.
Step 1 will build AST for both the Item and Item2 constructors. In step 2,
the only strong external symbol to emit as IR is main. main references the
DataSet default constructor, so we emit that. The DataSet default
constructor references the Item2 constructor, so we emit that. LLVM IR for
he Item constructor is never emitted because it's not used by this
translation unit.
Depending on what you want to do for your research purposes, you could
either look at the AST rather than the IR, or use the -femit-all-decls flag
to ask Clang to emit declarations even if they're unused.
>
> - I tried to forcibly insert constructor using
> "DeclareImplicitDefaultConstructor or DefineImplicitDefaultConstructor" and
> check other possible functions such as "ShouldDeleteSpecialMember" (in
> SemaDeclCXX.cpp).
> - However, I could not find an answer yet.
>
> Thank you very much.
>
> Best regards,
> Y. Jeon.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200324/9ee55472/attachment.html>
More information about the cfe-dev
mailing list