From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6847 invoked by alias); 5 Apr 2010 13:50:51 -0000 Received: (qmail 6829 invoked by uid 22791); 5 Apr 2010 13:50:50 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SARE_MSGID_LONG45,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-ww0-f47.google.com (HELO mail-ww0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Apr 2010 13:50:45 +0000 Received: by wwb13 with SMTP id 13so2598820wwb.20 for ; Mon, 05 Apr 2010 06:50:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.11.209 with HTTP; Mon, 5 Apr 2010 06:50:42 -0700 (PDT) Date: Mon, 05 Apr 2010 13:50:00 -0000 Received: by 10.216.173.74 with SMTP id u52mr3395881wel.204.1270475442903; Mon, 05 Apr 2010 06:50:42 -0700 (PDT) Message-ID: Subject: Processing global static (or const) variables From: Ehren Metcalfe To: gcc@gcc.gnu.org Cc: tglek@mozilla.com, jason@redhat.com Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg00056.txt.bz2 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