Question

i've been playing around with the gcc 4.6 plugin api. For convenience i use a python wrapper/plugin for the api.

My goal ist to find the declarations of all variables with:

  • global scope
  • and not const
  • and not static (means exported or visible)

in a compilation unit and emit a warning. for eg:

int glob;              // exported
static int moduleGlob; // not exported
const int aModConst=42;
int f() {static int inner; return inner;}

should yield "glob"

"outside of functions/classes" and "const" is easy, but i can't get the "static" qualifier.

I am crawling the global namespace subtree and watch for VAR_DECL nodes not having the const flag.

But how is the "static" keyword handled? It does not seem to be one of the bitfield-flags. Also the "static predicate" on the node is misleading because it simply says that the variable goes in the static storage (which glob does - but also moduleGlob and inner). My questions rather is "will it be exported on a .so"

What about a "extern" declaration? How is that mapped in the AST?

Currently i try to do this in the *free_lang_data pass (is this too late?)

The only hint i have so far is this: When dumping the tree via the -fdump-tree-all switch is in the .tu dump there is an additional node whith the mangled name of the global variable (in the nonstatic case).

Any ideas how i could solve this?

No correct solution

OTHER TIPS

From the documentation, it looks like you should use DECL_THIS_STATIC and DECL_THIS_EXTERN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top