This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: More __comp_ctor () woes


Hi all,

Well after trying numerous different approaches to find the FUNCTION_DECL node for a constructor like MyClass::MyClass(int) from a FUNCTION_DECL node for one of the constructors: MyClass::__comp_ctor (int) or similar, I have found that there is a VERY simple way to do this using DECL_CLONED_FUNCTION()


I am posting my understanding here in case others are searching for the same information in the future.


The __comp_ctor (), __base_ctor (), and similarly __comp_dtor () ... like functions are created as clones of what i call "user constructors".

I.e. for the code:

class MyClass
{
public:
   MyClass(int i) {}
};

GCC will generate:

1) MyClass::__comp_ctor (int)
2) MyClass::__base_ctor (int)
3) MyClass::MyClass(int)

Item (3) contains the users code for the constructor. At some point GCC then gets the FUNCTION_DECL node for (3) and creates two "clones" of (3) which are (1) and (2) I think these are referred to as in-charge and not in-charge constructors. From what I understand these clones are just an alias for the original function. However you are unable to get the DECL_SAVED_TREE() from them which gives the actual code for the constructor.

All code that uses constructors will make use of these __comp_ctor () and __base_ctor () like functions and NOT the user defined MyClass() constructor, i think this is done because it is simpler than the alternative of trying to use the MyClass::MyClass(int) function directly.

Anyhow, the simple way of finding the original function (3) from any clone (1) and (2) is to use the macro: DECL_CLONED_FUNCTION(fndecl). For a function that is a clone of another function, this will return the original function that was cloned, in our case (3)

I failed to understand what it is meant when a function is a clone, and so assumed that the "implementation" of the __comp_ctor () function (which is a clone) would have a CALL_EXPR node in it somewhere for the (3) FUNCTION_DECL, where from what i understand now it seems to just be an alias for it.

Part of what I have found confusing is that there are "deleting" destructors, which made me think that there was some extra code as part of this __deleting_dtor () that woud free the memory or something like that. Maybe this is the case, but I do not need to know that for my situation.

Hope this can help someone else.

Thanks,
Brendon.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]