On Sat, Dec 5, 2020 at 1:55 AM Martin Sebor via Gcc <gcc@gcc.gnu.org> wrote:
>
> On 12/4/20 4:33 PM, Martin Sebor wrote:
> > I'm looking for a way to get the FUNCTION_DECL for the library
> > (i.e., non-built-in) form of a function given the corresponding
> > built-in DECL.  Is there an API I can all with either the built
> > -in DECL or its code to get it in the middle end?
> >
> > In C, what I'm looking for appears to be DECL_CHAIN(decl), at
> > least for the example I looked at.  I.e., the library libdecl
> > for a corresponding __bultin_xxx DECL is DECL_CHAIN (DECL).
> >
> > But in C++, it looks like it's the other way around and it's
> > the built-in decl that's the DECL_CHAIN(DECL) for the built-in
> > DECL, and AFAIK there's no good way to get from the latter to
> > the former.
>
> To expand on this: I expected to get the library DECL for
> a declared function by calling
> symtab_node::get_from_asmname(libname) like for instance:
>
>    tree id = get_identifier ("free");
>    symtab_node *node = symtab_node::get_from_asmname (id);
>
> but what I get back is a DECL for __builtin_free instead.
> The DECL for "free" is the result of DECL_CHAIN() in C but
> not in C++.

The C family FEs aggressively "merge" decls, but usually
from builtin into the user provided one.  Did you see whether
node->next_sharing_asm_name get's you anywhere?
(I've always wanted to see the user provided decl prevail
in what builtin_decl_implicit returns)

DECL_CHAIN on these is purely FE local from their global
name bindings structures, we should probably clear it
somewhere (LTO doesn't write it for example).

Richard.

>
> >
> > Thanks
> > Martin
> >
> >
> >
> >
>

Reply via email to