This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Access to unused global variable declarations from a plugin
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: David Malcolm <dmalcolm at redhat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 9 Jan 2012 10:27:43 +0100
- Subject: Re: Access to unused global variable declarations from a plugin
- References: <1325780195.3719.88.camel@surprise>
On Thu, Jan 5, 2012 at 5:16 PM, David Malcolm <dmalcolm@redhat.com> wrote:
> I'm working on a GCC plugin which performs static analysis of Python
> extension code [1]
>
> In various places I need access to a VAR_DECL for various globals from C
> code, many of which potentially aren't used directly within the
> compilation unit. ?For example, I may need to reference this global:
> ? extern PyObject * PyExc_MemoryError;
> when reasoning about the possible exception objects that could have been
> set within a function, even if the code in question doesn't explicitly
> reference that global.
>
> Previously, I've been looking with the TRANSLATION_UNIT_DECL's block,
> and then looking within BLOCK_VARS().
>
> This works with 4.6.1, but doesn't work in 4.7 [2]; on debugging, it
> seems to have been broken by the fix for PR debug/51410:
> ?http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51410
> which seems to be slimming down the debuginfo by removing these decls.
>
> I suspect I was going about this the wrong way - so is there a good way
> to access VAR_DECLs for global variable declarations? (as opposed to
> *definitions*, which I'm able to access via "varpool_nodes").
> Previously I'd also tried looking them up via an identifier, but by the
> time my code runs the scope's binding from the identifier to the
> VAR_DECL has been lost.
>
> FWIW I'm tracking the breakage on my side as
> https://fedorahosted.org/gcc-python-plugin/ticket/21
Mere declarations are gone and not kept as you leave the frontends
domain. You can probably access them in frontend specific ways
before cgraph_finalize_compilation_unit is called.
Richard.
> Thanks
> Dave
>
> [1] https://fedorahosted.org/gcc-python-plugin/
> [2] specifically, on Fedora's builds of GCC, with
> gcc-4.6.1-9.fc15.x86_64 and gcc-4.7.0-0.2.fc17.x86_64 respectively
>
>