Re: detect empty functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 6, 2014 at 5:34 PM, Florian Weimer <fweimer@xxxxxxxxxx> 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




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux