From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3333 invoked by alias); 5 Apr 2010 14:20:53 -0000 Received: (qmail 3325 invoked by uid 22791); 5 Apr 2010 14:20:52 -0000 X-SWARE-Spam-Status: No, hits=1.6 required=5.0 tests=BAYES_50,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SARE_MSGID_LONG45 X-Spam-Check-By: sourceware.org Received: from mail-gw0-f47.google.com (HELO mail-gw0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Apr 2010 14:20:48 +0000 Received: by gwj21 with SMTP id 21so2252394gwj.20 for ; Mon, 05 Apr 2010 07:20:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.151.79.14 with HTTP; Mon, 5 Apr 2010 07:20:46 -0700 (PDT) In-Reply-To: References: Date: Mon, 05 Apr 2010 14:20:00 -0000 Received: by 10.150.168.1 with SMTP id q1mr6845711ybe.132.1270477246174; Mon, 05 Apr 2010 07:20:46 -0700 (PDT) Message-ID: Subject: Re: Processing global static (or const) variables From: Richard Guenther To: Ehren Metcalfe Cc: gcc@gcc.gnu.org, tglek@mozilla.com, jason@redhat.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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/msg00057.txt.bz2 On Mon, Apr 5, 2010 at 3:50 PM, Ehren Metcalfe 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)= { > =A0tree t =3D *tp; > > =A0if (TREE_CODE(t) =3D=3D FUNCTION_DECL) { > =A0 =A0// dump function > =A0} > > =A0return NULL_TREE; > } > > static void find_funcs(tree decl) { > =A0walk_tree(&decl, find_funcs_callback, NULL, NULL); > } > > // elsewhere > struct varpool_node *vnode; > FOR_EACH_STATIC_VARIABLE(vnode) > =A0find_funcs(DECL_INITIAL(vnode->decl)); > > ----- > > Unfortunately this doesn't work for code like this: > > ----- > > int foo() { > =A0return 0; > } > > typedef struct { > =A0int (*p) (); > } Table; > > const /* or static, or const static */ Table t[] =3D { > =A0{ 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 >