detect empty functions
Prathamesh Kulkarni
bilbotheelffriend@gmail.com
Thu Feb 6 14:16:00 GMT 2014
On Thu, Feb 6, 2014 at 5:34 PM, Florian Weimer <fweimer@redhat.com> wrote:
> On 02/05/2014 03:30 PM, Prathamesh Kulkarni wrote:
>>
>> I wanted to ask, is there a way to detect if a function has empty body
>> using GCC API ?
>
>
> Yes, you can write a plug-in and iterate over all the basic blocks in a
> function and check if they are empty.
I was looking for a way to detect empty function at GENERIC level.
Is the following correct way to do it ?
bool
is_tree_empty_function (tree fn)
{
tree body, kid;
body = DECL_SAVED_TREE (fn);
if (!body)
return false;
kid = TREE_OPERAND (body, 1);
gcc_assert (kid);
return TREE_CODE (kid) == STATEMENT_LIST && (STATEMENT_LIST_HEAD
(kid) == NULL);
}
>
> A function-like entity which contains no statements might still emit code,
> so you need to figure what you need exactly.
>
> --
> Florian Weimer / Red Hat Product Security Team
More information about the Gcc-help
mailing list