On 15 June 2011 18:14, charfi asma <charfiasma@xxxxxxxx> wrote: > Hello, > > I built a new gcc front end that produce this GIMPLE: > > main () > gimple_bind < > <unnamed-signed:32> D.35; > struct MyClass x; > > gimple_call <MyOperation1, NULL, &x> > gimple_assign <integer_cst, D.35, 0, NULL> > gimple_return <D.35> >> > > > MyOperation1 (struct MyClass * this) > gimple_bind < > gimple_assign <integer_cst, My_Var, 100, NULL> > gimple_assign <integer_cst, this->MyAttribute1, 50, NULL> > gimple_return <NULL> >> > > > which is equivalent to the C++ code: > > class MyClass > { > public: void MyOperation1() > { > int My_Var=10; > My_Var=100; > myAttribute=50; > > } > int myAttribute; > > }; > > int main() > { > MyClass x ; > x.MyOperation1(); > return 0; > } > > > when I run my compiler (called guml) : guml test.uml -fdump-tree-gimple-raw > , it generates the gimple above. > however when I run it using -O1, O2, O3 or Os guml test.uml > -fdump-tree-gimple-raw -Os, it generates a seg fault. > > I used gdb to debug, and I discover that the error comes from the modifications > of MyAttribute1 gimple_assign <integer_cst, this->MyAttribute1, 50, NULL> > because if I remove the equivalent GENERIC tree, the compilation works fine even > with -Os. > > the error comes more precisely when tring to run the ipa optimisations > > Analyzing compilation unit > Performing interprocedural optimizations > <*free_lang_data> <visibility> <early_local_cleanups> > Breakpoint 1, execute_ipa_pass_list (pass=0x1168800) at > ../../gcc/gcc/passes.c:1928 > 1928 do_per_function_toporder ((void (*)(void > *))execute_pass_list, > ...... > 1131 for (i = nnodes - 1; i >= 0; i--) > (gdb) n > 1133 struct cgraph_node *node = order[i]; > (gdb) n > 1136 order[i] = NULL; > (gdb) n > 1137 node->process = 0; > (gdb) n > 1138 if (node->analyzed) > (gdb) n > 1140 push_cfun (DECL_STRUCT_FUNCTION (node->decl)); > (gdb) n > 1141 current_function_decl = node->decl; > (gdb) n > 1142 callback (data); > (gdb) n > 1141 current_function_decl = node->decl; > (gdb) n > 1142 callback (data); > (gdb) n > > Program received signal SIGSEGV, Segmentation fault. > fold_convertible_p (type=0x0, arg=0x7f2bf778a1e0) at > ../../gcc/gcc/fold-const.c:1830 > 1830 || TREE_CODE (orig) == ERROR_MARK) > > > In a normal compilation, the debugger should print: > Performing interprocedural optimizations > <*free_lang_data> <visibility> <early_local_cleanups> <whole-program> > <inline>Assembling functions: > MyOperation1 main > > > so I think that the error comes from Whole-program optimization. > > This is how I set MyOperation1() body > > tree __func_param = NULL_TREE; > tree parm_type = build_pointer_type(class_t); > tree parm = build_decl (BUILTINS_LOCATION, PARM_DECL, get_identifier("this"), > parm_type); > TREE_CONSTANT (parm) = true; > TREE_READONLY (parm) = true; > > > DECL_CHAIN (parm) = __func_param; > __func_param = parm; > DECL_ARGUMENTS(operation)=(__func_param); > > > // return type preparation > > tree __func_result = build_decl(BUILTINS_LOCATION, RESULT_DECL, NULL_TREE, > TREE_TYPE(operation)); > DECL_CONTEXT(__func_result) = operation; > DECL_ARTIFICIAL(__func_result) = true; > DECL_IGNORED_P(__func_result) = true; > DECL_RESULT(operation) = __func_result; > > > // debug tree needed for bind exp > > tree __func_art_block = build_block(NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); > DECL_INITIAL(operation) = __func_art_block; > > > //stmt tree for the body > > tree func_stmts = alloc_stmt_list (); > > //set the body > > tree var = build_decl(BUILTINS_LOCATION, VAR_DECL, get_identifier("My_Var"), > integer_type_node); > TREE_STATIC(var) = true; > TREE_PUBLIC(var) = true; > DECL_CONTEXT(var) = operation; > TREE_USED(var) = true; > DECL_INITIAL (var) = build_int_cst(integer_type_node, 10 ); > > layout_decl(var, false); > rest_of_decl_compilation(var, 1, 0); > > append_to_statement_list(var, &func_stmts); > > > tree val = build_int_cst(integer_type_node, 100); > tree modify_att_tree = build2(MODIFY_EXPR, TREE_TYPE(var), var, val); > > append_to_statement_list(modify_att_tree, &func_stmts); > > > tree t = TREE_TYPE(TREE_TYPE(parm)); > > tree ref = build1 (INDIRECT_REF, t, parm); > > tree __struct_field0 = TYPE_FIELDS(TREE_TYPE(ref)); > > tree __struct_access_0 = build3(COMPONENT_REF, TREE_TYPE(__struct_field0), > ref, __struct_field0, NULL_TREE); > > tree modify_att_tree0 = build2(MODIFY_EXPR, TREE_TYPE(__struct_field0), > __struct_access_0, build_int_cst(integer_type_node, 50)); > > append_to_statement_list(modify_att_tree0, &func_stmts); > > > // add the final return statement > > tree func_ret_expr = build1(RETURN_EXPR, void_type_node, NULL_TREE); > > append_to_statement_list(func_ret_expr, &func_stmts); > > > // bind and gimplification > > DECL_SAVED_TREE(operation) = build3(BIND_EXPR, void_type_node, NULL_TREE, > func_stmts, __func_art_block); > > > // pass to middle end > > gimplify_function_tree(operation); > cgraph_node(operation); > cgraph_finalize_function(operation,false); > > > did I miss something ? > > thank you very much > > Asma > To be fair it could be a problem with the gcc sources your compiling with that was maybe fixed in the next commit or something. I remember having a problem like that before but then in my repository i just added the gcc git mirror and did: git add remote gcc git://gcc.gnu.org/git/gcc.git git fetch gcc git merge gcc/master And make clean && make And it worked fine, i cant see any immediate error, as it already compiles with O0 i assume. --Phi