This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Access to unused global variable declarations from a plugin
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 05 Jan 2012 11:16:34 -0500
- Subject: Access to unused global variable declarations from a plugin
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
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