public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ehren Metcalfe <ehren.m@gmail.com>
To: gcc@gcc.gnu.org
Cc: tglek@mozilla.com, jason@redhat.com
Subject: Processing global static (or const) variables
Date: Mon, 05 Apr 2010 13:50:00 -0000	[thread overview]
Message-ID: <g2j934be2481004050650te6ca4888td57fdf83f1323ae5@mail.gmail.com> (raw)

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

             reply	other threads:[~2010-04-05 13:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-05 13:50 Ehren Metcalfe [this message]
2010-04-05 14:20 ` Richard Guenther
2010-04-06  3:50   ` Ehren Metcalfe
2010-04-06  8:49     ` Richard Guenther

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=g2j934be2481004050650te6ca4888td57fdf83f1323ae5@mail.gmail.com \
    --to=ehren.m@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=tglek@mozilla.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).