Constructing static variables in GIMPLE?

Sean Callanan spyffe@cs.sunysb.edu
Fri Jun 13 05:57:00 GMT 2008


Dear mailing list:

I am writing GCC code that constructs GIMPLE (after pass_apply_inline  
and before pass_all_optimizations) for a function-level static  
variable that gets assigned to and passed to another function.  My  
problem is that I am getting undefined symbol errors for a renamed  
version of the symbol.
I define the variable as below:

--
static tree build_static(tree type, const char* name)
{
   tree ret = NULL;

   ret = build_decl(VAR_DECL, get_identifier(name), type);

   DECL_ARTIFICIAL(ret) = 1;     // declared by the compiler
   DECL_IGNORED_P(ret) = 1;      // no debug info
   TREE_READONLY(ret) = 0;       // writable
   DECL_EXTERNAL(ret) = 0;       // defined
   TREE_STATIC(ret) = 1;         // static
   TREE_USED(ret) = 1;           // used
   DECL_CONTEXT(ret) = cfun->decl;

   create_var_ann(ret);
   add_referenced_var(ret);

   return ret;
}
--

Here's an example where I use this function, and demonstrating how I  
use the variable.

--
   tree last_p = build_static(long_long_unsigned_type_node, "last_p");
   // ...
   tree subtraction = build2(MINUS_EXPR, long_long_unsigned_type_node,  
end_time, start_time);
   build_gimple_modify_stmt(last_p, subtraction);
   // ...
   tree last_p_temp = create_tmp_var(TREE_TYPE(last_p),  
get_name(last_p));
   tree last_p_name = make_ssa_name(last_p_temp, NULL);
   tree last_p_assignment = build_gimple_modify_stmt(last_p_name,  
last_p);
   SSA_NAME_DEF_STMT(last_p_name) = last_p_assignment;
--

As seen above, I (try to) respect SSA when reading from this variable,  
and when assigning to it (I create an SSA_NAME when using the value,  
and assign directly to the VAR_DECL).  I'm passing an SSA_NAME to the  
function.  However, when I compile, I'm getting linker errors of the  
form:

--
[...]/test.c:4: undefined reference to `last_p.2610'
--

Oddly, I don't get undefined references for `last_p'; I find it very  
odd that it's being renamed.  Does anyone know what's going on here?   
As always, I welcome corrections to my (admittedly novice-level)  
GIMPLE- and SSA-fu.
Thanks for looking at this.

Sincerely,
Sean Callanan



More information about the Gcc mailing list