[cfe-dev] Where is default constructor delete function in clang?

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Tue Mar 24 10:59:20 PDT 2020


Ah, sorry, was confused a bit because you talked about "deleting
constructors" and I thought you meant in the C++ sense of "= delete".

You mean Clang didn't produce an actual llvm::Function for a constructor
when the constructor is trivial? Right right.

I'd suggest you start with the small/simple example of a non-trivial ctor
like and one with a trivial dtor:

struct t1 { t1(); };
struct t2 { };
int main() {
  t1 v1;
  t2 v2;
}

(I'd actually write these in two different programs, rather than all in one)

Then compile each of the two examples - run the compiler under a debugger,
break on, maybe llvm::Function's ctor, eventually you'll break on LLVM
making the ctor function, and you can trace back through the two debuggers
to try to figure out why one does make the ctor and why one doesn't and
modify the code there to always make it.


On Mon, Mar 23, 2020 at 7:45 PM 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)?
>
>    - 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/35e59935/attachment-0001.html>


More information about the cfe-dev mailing list