Hi, I am trying to implement a prototype pass that instruments a function to check for safe memory accesses. As a starting point I looked at mudflap1 pass, in tree-mudflap.c and decided that I should write a dummy pass ( very simple, but similar to mudflap) that instruments the code to count the number of functions in the source file.
I am unable to add a global variable in the file scope. The global VAR_DECL building function looks like this: { tree decl = build_decl (VAR_DECL, get_identifier ("my_var"), integer_type_node); TREE_PUBLIC (decl) = 0; DECL_EXTERNAL (decl) = 0; TREE_STATIC (decl) = 1; gimplify_stmt (my_variable); lang_hooks.decls.pushdecl (decl); return decl; } It is called from within my call-back function "execute_my_pass" ( as specified by me in the tree_opt_pass structure ). I increment "my_var" in every function. But, the instrumented object file doesnot have a storage allocated for this variable in the .data section. The problem is that DECL_CONTEXT of this VAR_DECL is always getting assigned to a function, and not to global file scope. Why is that? Any help would be appreciated. Thanks, Prateek.