public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem with instrumenting GIMPLE for adding a global variable
@ 2005-08-20 23:20 Prateek Saxena
  0 siblings, 0 replies; 2+ messages in thread
From: Prateek Saxena @ 2005-08-20 23:20 UTC (permalink / raw)
  To: gcc

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Problem with instrumenting GIMPLE for adding a global variable
@ 2005-08-20 23:53 Prateek Saxena
  0 siblings, 0 replies; 2+ messages in thread
From: Prateek Saxena @ 2005-08-20 23:53 UTC (permalink / raw)
  To: gcc

Sorry, my mistake. I initialized it with a value, and it appeared in
the .data. :)
  
> 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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-20 23:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-20 23:20 Problem with instrumenting GIMPLE for adding a global variable Prateek Saxena
2005-08-20 23:53 Prateek Saxena

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).