I think more correctly i am looking to define a VAR_DECL at file scope and not sure how. --Phil On 20 August 2013 16:04, Philip Herron <redbrain@xxxxxxxxxxx> wrote: > Hey > > I am wondering how do i have a global variable in GENERIC currently i am doing: > > tree stack_offset = build_decl (BUILTINS_LOCATION, VAR_DECL, > create_tmp_var_name ("__MODULE_STK_OFFS"), > sizetype); > > TREE_STATIC (stack_offset) = 1; > TREE_PUBLIC (stack_offset) = 1; > TREE_USED (stack_offset) = 1; > DECL_INITIAL (stack_offset) = build_int_cst (integer_type_node, 0); > rest_of_decl_compilation (stack_offset, 1, 0); > > Then i add this to the array of stuff you pass to the middle-end but i > am getting: > > <built-in>: In function ‘t.__main_start__’: > <built-in>:0:0: internal compiler error: in expand_expr_real_1, at expr.c:9326 > > Its this assert: > > /* Variables inherited from containing functions should have > been lowered by this point. */ > context = decl_function_context (exp); > gcc_assert (!context > || context == current_function_decl > || TREE_STATIC (exp) > || DECL_EXTERNAL (exp) > /* ??? C++ creates functions that are not TREE_STATIC. */ > || TREE_CODE (exp) == FUNCTION_DECL); > > So it must be because that has no context set but i the idea is that i > want in generic to be able to use this global variable: > > sizetype myglobal > > void myfunction () { > ... > sizetype x = myglobal + ... > } > > I hope this makes sense just not sure what the context needs to be set > to i think. > > --Phil