public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Processing global static (or const) variables
@ 2010-04-05 13:50 Ehren Metcalfe
  2010-04-05 14:20 ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Ehren Metcalfe @ 2010-04-05 13:50 UTC (permalink / raw)
  To: gcc; +Cc: tglek, jason

Hello,

I'm trying to develop a dead code finder using gcc and mozilla's
treehydra but I've hit a wall processing certain initializations of
global variables.

In order to mark a function declaration whenever its address is held
in a file scope variable/table/structure I use code like this:

-----

static tree find_funcs_callback(tree *tp, int *walk_subtrees, void *data) {
  tree t = *tp;

  if (TREE_CODE(t) == FUNCTION_DECL) {
    // dump function
  }

  return NULL_TREE;
}

static void find_funcs(tree decl) {
  walk_tree(&decl, find_funcs_callback, NULL, NULL);
}

// elsewhere
struct varpool_node *vnode;
FOR_EACH_STATIC_VARIABLE(vnode)
  find_funcs(DECL_INITIAL(vnode->decl));

-----

Unfortunately this doesn't work for code like this:

-----

int foo() {
  return 0;
}

typedef struct {
  int (*p) ();
} Table;

const /* or static, or const static */ Table t[] = {
  { foo }
};

-----

If I remove the qualifiers from my table the initialization is
detected. Is this a bug or is there some other way of recovering the
FUNCTION_DECL? It doesn't need to be modular, I just have to find a
way to dump the function.

Thanks,

Ehren

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Processing global static (or const) variables
  2010-04-05 13:50 Processing global static (or const) variables Ehren Metcalfe
@ 2010-04-05 14:20 ` Richard Guenther
  2010-04-06  3:50   ` Ehren Metcalfe
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Guenther @ 2010-04-05 14:20 UTC (permalink / raw)
  To: Ehren Metcalfe; +Cc: gcc, tglek, jason

On Mon, Apr 5, 2010 at 3:50 PM, Ehren Metcalfe <ehren.m@gmail.com> wrote:
> Hello,
>
> I'm trying to develop a dead code finder using gcc and mozilla's
> treehydra but I've hit a wall processing certain initializations of
> global variables.
>
> In order to mark a function declaration whenever its address is held
> in a file scope variable/table/structure I use code like this:
>
> -----
>
> static tree find_funcs_callback(tree *tp, int *walk_subtrees, void *data) {
>  tree t = *tp;
>
>  if (TREE_CODE(t) == FUNCTION_DECL) {
>    // dump function
>  }
>
>  return NULL_TREE;
> }
>
> static void find_funcs(tree decl) {
>  walk_tree(&decl, find_funcs_callback, NULL, NULL);
> }
>
> // elsewhere
> struct varpool_node *vnode;
> FOR_EACH_STATIC_VARIABLE(vnode)
>  find_funcs(DECL_INITIAL(vnode->decl));
>
> -----
>
> Unfortunately this doesn't work for code like this:
>
> -----
>
> int foo() {
>  return 0;
> }
>
> typedef struct {
>  int (*p) ();
> } Table;
>
> const /* or static, or const static */ Table t[] = {
>  { foo }
> };
>
> -----
>
> If I remove the qualifiers from my table the initialization is
> detected. Is this a bug or is there some other way of recovering the
> FUNCTION_DECL? It doesn't need to be modular, I just have to find a
> way to dump the function.

At which point during the compilation does it not work?  I suppose
at the point where the qualified variants are already optimized away.

Richard.

> Thanks,
>
> Ehren
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Processing global static (or const) variables
  2010-04-05 14:20 ` Richard Guenther
@ 2010-04-06  3:50   ` Ehren Metcalfe
  2010-04-06  8:49     ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Ehren Metcalfe @ 2010-04-06  3:50 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

(Apologies to Richard for sending this twice -- I forgot to cc the list)

> At which point during the compilation does it not work?  I suppose
> at the point where the qualified variants are already optimized away.

I've had some difficulty walking the DECL_INITIAL from within a
separate pass but I've added this code to the execute function of
pass_ipa_function_and_variable_visibility which should be about as
close to pass_build_cgraph_edges as I can get. Also the
record_references callback in cgraphbuild.c exhibits the same
behavior.

I get the same results with 4.3.4 and a recent checkout.

Is there a way to disable the optimizing away of qualified variants?
This seems to be a bug, especially with regard to
record_references_in_initializer and record_references in
cgraphbuild.c

On Mon, Apr 5, 2010 at 10:20 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Mon, Apr 5, 2010 at 3:50 PM, Ehren Metcalfe <ehren.m@gmail.com> wrote:
>> Hello,
>>
>> I'm trying to develop a dead code finder using gcc and mozilla's
>> treehydra but I've hit a wall processing certain initializations of
>> global variables.
>>
>> In order to mark a function declaration whenever its address is held
>> in a file scope variable/table/structure I use code like this:
>>
>> -----
>>
>> static tree find_funcs_callback(tree *tp, int *walk_subtrees, void *data) {
>>  tree t = *tp;
>>
>>  if (TREE_CODE(t) == FUNCTION_DECL) {
>>    // dump function
>>  }
>>
>>  return NULL_TREE;
>> }
>>
>> static void find_funcs(tree decl) {
>>  walk_tree(&decl, find_funcs_callback, NULL, NULL);
>> }
>>
>> // elsewhere
>> struct varpool_node *vnode;
>> FOR_EACH_STATIC_VARIABLE(vnode)
>>  find_funcs(DECL_INITIAL(vnode->decl));
>>
>> -----
>>
>> Unfortunately this doesn't work for code like this:
>>
>> -----
>>
>> int foo() {
>>  return 0;
>> }
>>
>> typedef struct {
>>  int (*p) ();
>> } Table;
>>
>> const /* or static, or const static */ Table t[] = {
>>  { foo }
>> };
>>
>> -----
>>
>> If I remove the qualifiers from my table the initialization is
>> detected. Is this a bug or is there some other way of recovering the
>> FUNCTION_DECL? It doesn't need to be modular, I just have to find a
>> way to dump the function.
>
> At which point during the compilation does it not work?  I suppose
> at the point where the qualified variants are already optimized away.
>
> Richard.
>
>> Thanks,
>>
>> Ehren
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Processing global static (or const) variables
  2010-04-06  3:50   ` Ehren Metcalfe
@ 2010-04-06  8:49     ` Richard Guenther
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Guenther @ 2010-04-06  8:49 UTC (permalink / raw)
  To: Ehren Metcalfe; +Cc: gcc

On Tue, Apr 6, 2010 at 5:50 AM, Ehren Metcalfe <ehren.m@gmail.com> wrote:
> (Apologies to Richard for sending this twice -- I forgot to cc the list)
>
>> At which point during the compilation does it not work?  I suppose
>> at the point where the qualified variants are already optimized away.
>
> I've had some difficulty walking the DECL_INITIAL from within a
> separate pass but I've added this code to the execute function of
> pass_ipa_function_and_variable_visibility which should be about as
> close to pass_build_cgraph_edges as I can get. Also the
> record_references callback in cgraphbuild.c exhibits the same
> behavior.

It should work there.

> I get the same results with 4.3.4 and a recent checkout.
>
> Is there a way to disable the optimizing away of qualified variants?
> This seems to be a bug, especially with regard to
> record_references_in_initializer and record_references in
> cgraphbuild.c
>
> On Mon, Apr 5, 2010 at 10:20 AM, Richard Guenther
> <richard.guenther@gmail.com> wrote:
>> On Mon, Apr 5, 2010 at 3:50 PM, Ehren Metcalfe <ehren.m@gmail.com> wrote:
>>> Hello,
>>>
>>> I'm trying to develop a dead code finder using gcc and mozilla's
>>> treehydra but I've hit a wall processing certain initializations of
>>> global variables.
>>>
>>> In order to mark a function declaration whenever its address is held
>>> in a file scope variable/table/structure I use code like this:
>>>
>>> -----
>>>
>>> static tree find_funcs_callback(tree *tp, int *walk_subtrees, void *data) {
>>>  tree t = *tp;
>>>
>>>  if (TREE_CODE(t) == FUNCTION_DECL) {
>>>    // dump function
>>>  }
>>>
>>>  return NULL_TREE;
>>> }
>>>
>>> static void find_funcs(tree decl) {
>>>  walk_tree(&decl, find_funcs_callback, NULL, NULL);
>>> }
>>>
>>> // elsewhere
>>> struct varpool_node *vnode;
>>> FOR_EACH_STATIC_VARIABLE(vnode)
>>>  find_funcs(DECL_INITIAL(vnode->decl));
>>>
>>> -----
>>>
>>> Unfortunately this doesn't work for code like this:
>>>
>>> -----
>>>
>>> int foo() {
>>>  return 0;
>>> }
>>>
>>> typedef struct {
>>>  int (*p) ();
>>> } Table;
>>>
>>> const /* or static, or const static */ Table t[] = {
>>>  { foo }
>>> };
>>>
>>> -----
>>>
>>> If I remove the qualifiers from my table the initialization is
>>> detected. Is this a bug or is there some other way of recovering the
>>> FUNCTION_DECL? It doesn't need to be modular, I just have to find a
>>> way to dump the function.
>>
>> At which point during the compilation does it not work?  I suppose
>> at the point where the qualified variants are already optimized away.
>>
>> Richard.
>>
>>> Thanks,
>>>
>>> Ehren
>>>
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-06  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-05 13:50 Processing global static (or const) variables Ehren Metcalfe
2010-04-05 14:20 ` Richard Guenther
2010-04-06  3:50   ` Ehren Metcalfe
2010-04-06  8:49     ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).