This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Identifying declared but unreferenced global variables from a plugin
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "Bertram, Alexander" <alex at bedatadriven dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 17 Jun 2016 10:18:24 +0100
- Subject: Re: Identifying declared but unreferenced global variables from a plugin
- Authentication-results: sourceware.org; auth=none
- References: <CAOdV3zCp=S+XQPoeh8ejmT6YxuEoN2gGmau8qC4vXQ0w2b4G4g at mail dot gmail dot com>
On 17 June 2016 at 08:38, Bertram, Alexander wrote:
> Hi there,
>
> I'm trying to get the gcc-bridge plugin to dump out a list of _all_
> global variables declared within a translation unit, even if they're
> not used, and I've really hit a brick wall. Can anyone point me in the
> right direction?
>
> In more detail, say that you have a C source file consisting only of:
>
> int magic_number = 42;
>
> With no functions declared. The global variable and its data is
> written to the object file:
>
> $ gcc -c link1.c
> $ nm link1.o
> 0000000000000000 D magic_number
>
> But the global variable is not referenced by any functions so the
> plugin never encounters it and doesn't know it exists.
If I understand correctly, all the current plugin hooks are in the
code-generation stages. If a variable is unused and so never gets
emitted by the front-end, then the code-gen passes won't see it, and
your plugin won't see it.
I want to write a plugin that inspects the names of all declarations,
including unused variables/functions and uninstantiated templates, but
it can't be done today. I opened
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70757 to ask for extra
plugin hooks.