[committed] analyzer: detect malloc, free, calloc within "std" [PR93959]
Marek Polacek
polacek@redhat.com
Wed Mar 4 16:05:00 GMT 2020
On Wed, Mar 04, 2020 at 04:54:54PM +0100, Bernhard Reutner-Fischer wrote:
> On Mon, 2 Mar 2020 16:48:26 -0500
> David Malcolm <dmalcolm@redhat.com> wrote:
>
> > +static inline bool
> > +is_std_function_p (const_tree fndecl)
> > +{
> > + tree name_decl = DECL_NAME (fndecl);
> > + if (!name_decl)
> > + return false;
> > + if (!DECL_CONTEXT (fndecl))
> > + return false;
> > + if (TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
> > + return false;
> > + tree ns = DECL_CONTEXT (fndecl);
> > + if (!(DECL_CONTEXT (ns) == NULL_TREE
> > + || TREE_CODE (DECL_CONTEXT (ns)) == TRANSLATION_UNIT_DECL))
> > + return false;
> > + if (!DECL_NAME (ns))
> > + return false;
> > + return id_equal ("std", DECL_NAME (ns));
> > +}
>
> Sounds a bit elaborate, doesn't?
> I hope this is optimized to
>
> static inline bool
> is_std_function_p (const_tree fndecl)
> {
> tree name_decl = DECL_NAME (fndecl);
> if (!name_decl)
> return false;
> tree ns = DECL_CONTEXT (fndecl);
> if (!ns)
> return false;
> if (TREE_CODE (ns) != NAMESPACE_DECL)
> return false;
> if (!(DECL_CONTEXT (ns) == NULL_TREE
> || TREE_CODE (DECL_CONTEXT (ns)) == TRANSLATION_UNIT_DECL))
> return false;
> if (!DECL_NAME (ns))
> return false;
> return id_equal ("std", DECL_NAME (ns));
> }
>
> isn't "std" spelled out std_identifier() and is an identifier, i.e.
> return DECL_NAME (ns) == std_identifier; ?
We have decl_in_std_namespace_p for that.
Marek
More information about the Gcc-patches
mailing list