This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Processing global static (or const) variables
- From: Ehren Metcalfe <ehren dot m at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Cc: tglek at mozilla dot com, jason at redhat dot com
- Date: Mon, 5 Apr 2010 09:50:42 -0400
- Subject: Processing global static (or const) variables
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