This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
[GENERIC] problem when adding 2 VAR_DEC in the main function
- From: charfi asma <charfiasma at yahoo dot fr>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 20 Oct 2010 11:30:10 +0100 (BST)
- Subject: [GENERIC] problem when adding 2 VAR_DEC in the main function
Hello,
after compiling int main () { return 0;} by writing by hend GENERIC tree code, I
tried to add a var dec in the main function ( int x=10);
1. I added this to my compiler code in the parse_file hook :
tree __glob_decl = build_decl(BUILTINS_LOCATION, VAR_DECL, get_identifier("x"),
integer_type_node);
TREE_STATIC(__glob_decl) = false;
TREE_PUBLIC(__glob_decl) = true;
DECL_CONTEXT(__glob_decl) = main_fn_decl;
TREE_USED(__glob_decl) = true;
tree global_set = build2(INIT_EXPR, TREE_TYPE( __glob_decl), __glob_decl,
build_int_cst(integer_type_node, 10));
TREE_USED(global_set) = true;
append_to_statement_list(global_set, &main_stmts);
layout_decl(__glob_decl, false);
rest_of_decl_compilation(__glob_decl, 1, 0);
VEC_safe_push( tree, gc, global_decls_vec, __glob_decl );
tree bind = NULL_TREE;
tree bl = build_block(__glob_decl, NULL_TREE, main_fn_decl, NULL_TREE);
DECL_INITIAL(main_fn_decl) = bl;
TREE_USED(bl) = 1;
bind = build3( BIND_EXPR, void_type_node, BLOCK_VARS(bl), NULL_TREE, bl );
TREE_SIDE_EFFECTS(bind) = 1;
BIND_EXPR_BODY(bind) = main_stmts;
main_stmts = bind;
DECL_SAVED_TREE(main_fn_decl) = main_stmts;
2. and this code in the write_global hook :
int idx, idy=0, len= VEC_length(tree,global_decls_vec);
tree itx = NULL_TREE;
tree * vec = XNEWVEC( tree, len );
for( idx=0; VEC_iterate(tree,global_decls_vec,idx,itx); ++idx )
{
vec[ idy ] = itx;
idy++;
}
wrapup_global_declarations( vec, len );
check_global_declarations( vec, len );
emit_debug_global_declarations( vec, len );
cgraph_finalize_compilation_unit( );
free( vec );
it compiles and generate the appropriate gimple (just like the gimple generated
when compiling the same c code using gcc )
main ()
gimple_bind <
<unnamed-signed:32> D.20;
<unnamed-signed:32> x;
gimple_assign <integer_cst, x, 1264, NULL>
gimple_assign <integer_cst, D.20, 0, NULL>
gimple_return <D.20>
>
the problem comes when I tried to add another variable in the same function
main: int y =5;
I added the same code related to x by changing x and y :
tree __glob_decl2 = build_decl(BUILTINS_LOCATION, VAR_DECL, get_identifier("y"),
integer_type_node);
TREE_STATIC(__glob_decl2) = false;
TREE_PUBLIC(__glob_decl2) = true;
DECL_CONTEXT(__glob_decl2) = main_fn_decl;
TREE_USED(__glob_decl2) = true;
tree global_set2 = build2(INIT_EXPR, TREE_TYPE( __glob_decl), __glob_decl,
build_int_cst(integer_type_node, 5));
TREE_USED(global_set2) = true;
append_to_statement_list(global_set2, &main_stmts);
layout_decl(__glob_decl2, false);
rest_of_decl_compilation(__glob_decl2, 1, 0);
VEC_safe_push( tree, gc, global_decls_vec, __glob_decl2 );
.....
but I get this error while compiling:
[root@is010178 test_gcalc]# guml test.uml -S -fdump-tree-gimple-raw
<built-in>: In function âmainâ:
<built-in>:0:0: internal compiler error: in gimplify_var_or_parm_decl, at
gimplify.c:1874
it seems that the function gimplify_var_or_parm_decl consider that I have a
duplicate declaration.
any idea ? did I miss sth ??
thank you very much.
Asma