From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5957 invoked by alias); 27 Jan 2011 10:43:31 -0000 Received: (qmail 5944 invoked by uid 22791); 27 Jan 2011 10:43:30 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RFC_ABUSE_POST,TW_TM,T_FRT_BELOW2 X-Spam-Check-By: sourceware.org Received: from nm16.bullet.mail.ukl.yahoo.com (HELO nm16.bullet.mail.ukl.yahoo.com) (217.146.183.190) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Thu, 27 Jan 2011 10:43:24 +0000 Received: from [217.146.183.215] by nm16.bullet.mail.ukl.yahoo.com with NNFMP; 27 Jan 2011 10:43:22 -0000 Received: from [217.146.183.175] by tm8.bullet.mail.ukl.yahoo.com with NNFMP; 27 Jan 2011 10:43:22 -0000 Received: from [127.0.0.1] by omp1016.mail.ukl.yahoo.com with NNFMP; 27 Jan 2011 10:43:22 -0000 Received: (qmail 53756 invoked by uid 60001); 27 Jan 2011 10:43:22 -0000 Message-ID: <995721.52571.qm@web28511.mail.ukl.yahoo.com> Received: from [132.166.132.113] by web28511.mail.ukl.yahoo.com via HTTP; Thu, 27 Jan 2011 10:43:21 GMT References: <629860.92100.qm@web28514.mail.ukl.yahoo.com> <4D40BAE5.7060904@andihellmund.com> Date: Thu, 27 Jan 2011 10:43:00 -0000 From: charfi asma Subject: Re : [Generic] change the value of an attribute To: Andi Hellmund Cc: gcc-help@gcc.gnu.org In-Reply-To: <4D40BAE5.7060904@andihellmund.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg00391.txt.bz2 ----- Message d'origine ---- De : Andi Hellmund =C0 : charfi asma Cc : gcc-help@gcc.gnu.org Envoy=E9 le : Jeu 27 janvier 2011, 1h 23min 01s Objet : Re: [Generic] change the value of an attribute On 01/26/2011 05:08 PM, charfi asma wrote: > Hello every body, > > I have a class named MyClass, that has an operation (MyOperation1) and th= is > operation change the value of MyAttribute1 of type Integer. > > to call my operation in the main I added a hidden argument (this) > > main > { > > tree myClass_type =3D make_node(RECORD_TYPE); > TYPE_PACKED(myClass_type) =3D false; > TYPE_NAME(myClass_type) =3D get_identifier("MyClass"); > > //properties: > > tree myAttribute1_type =3D integer_type_node; > tree myAttribute1_tree =3D build_decl(BUILTINS_LOCATION, FIELD_DECL, > get_identifier("MyAttribute1"), myAttribute1_type); > DECL_CONTEXT(myAttribute1_tree) =3D myClass_type; > DECL_PACKED(myAttribute1_tree) =3D false; > TYPE_FIELDS(myClass_type) =3D myAttribute1_tree; > > //operations: > > tree myOperation2_type =3D build_function_type_list(void_type_node, > NULL_TREE); > > tree myOperation2_decl =3D build_decl(BUILTINS_LOCATION, FUNCTION_DE= CL, > get_identifier("MyOperation2"), myOperation2_type); > tree myOperation2_tree =3D create_operation(myClass_type,=20 >myOperation2_decl); > // find bellow > > DECL_CONTEXT(myOperation2_tree) =3D myClass_type; > DECL_PACKED(myOperation2_tree) =3D false; > TYPE_METHODS(myClass_type) =3D myOperation2_tree; > > layout_type(myClass_type); > rest_of_type_compilation(myClass_type, 1); > > // create instance > > tree x_tree =3D build_decl(BUILTINS_LOCATION, VAR_DECL,=20 get_identifier("x"), > myClass_type); > TREE_STATIC(x_tree) =3D false; > TREE_PUBLIC(x_tree) =3D true; > DECL_CONTEXT(x_tree) =3D main_fn_decl; > TREE_USED(x_tree) =3D true; > > append_to_statement_list(x_tree,&main_stmts); > layout_decl(x_tree, false); > rest_of_decl_compilation(x_tree, 1, 0); > VEC_safe_push( tree, gc, global_decls_vec, x_tree ); > > // call operation > > tree target_ptr =3D build1(ADDR_EXPR, > build_pointer_type(TREE_TYPE(x_tree)),x_tree); //&x > > tree call_myOperation2 =3D build_call_expr(myOperation2_tree, 1,=20= =20 >target_ptr); > append_to_statement_list(call_myOperation2,&main_stmts); > > ... > } > > Now, I want to modify the value of MyAttribute1 in the operation body. ( > this.MyAttribute1=3D10) > > tree create_operation(tree class_t, tree operation ) > { > > > // set argument manually > > tree __func_param =3D NULL_TREE; > tree parm_type =3D build_pointer_type(class_t); > tree parm =3D build_decl (BUILTINS_LOCATION, PARM_DECL, get_identifier("t= his"), > parm_type); > TREE_CONSTANT (parm) =3D true; > TREE_READONLY (parm) =3D true; > > > DECL_CHAIN (parm) =3D __func_param; > __func_param =3D parm; > DECL_ARGUMENTS(operation)=3D(__func_param); > > > // return type preparation > tree __func_result =3D build_decl(BUILTINS_LOCATION, RESULT_DECL, NULL_TR= EE, > TREE_TYPE(operation)); > DECL_CONTEXT(__func_result) =3D operation; > DECL_ARTIFICIAL(__func_result) =3D true; > DECL_IGNORED_P(__func_result) =3D true; > DECL_RESULT(operation) =3D __func_result; > > // debug tree needed for bind exp > tree __func_art_block =3D build_block(NULL_TREE, NULL_TREE, NULL_TREE,=20 >NULL_TREE); > DECL_INITIAL(operation) =3D __func_art_block; > > tree func_stmts =3D alloc_stmt_list (); > > //set the body > > > tree t =3D TREE_TYPE(TREE_TYPE(parm)); > > tree ref =3D build1 (INDIRECT_REF, t, parm); > > tree __struct_field0 =3D TYPE_FIELDS(TREE_TYPE(ref)); > > tree __struct_access_0 =3D build3(COMPONENT_REF,=20 TREE_TYPE(__struct_field0), > ref, __struct_field0, NULL_TREE); > > tree modify_att_tree =3D build2(MODIFY_EXPR, TREE_TYPE(__struct_fiel= d0), > __struct_access_0, build_int_cst(integer_type_node, 10)); > > append_to_statement_list(modify_att_tree,&func_stmts); > > /********************************add the final return statement > *********************************/ > > tree func_ret_expr =3D build1(RETURN_EXPR, void_type_node, NULL_TREE); > > append_to_statement_list(func_ret_expr,&func_stmts); > > > // bind and gimplification > DECL_SAVED_TREE(operation) =3D build3(BIND_EXPR, void_type_node, NULL_TRE= E, > func_stmts, __func_art_block); > > // pass to middle end > gimplify_function_tree(operation); > cgraph_node(operation); > cgraph_finalize_function(operation,false); > > return operation; > > } > > I get error while calling gimplify_function_tree(operation); it comes from > COMPONENT_REF gimplification (call to gimplify_compound_lval) > > this is the debug output: > > (gdb) n > 7771 bind =3D gimplify_body (&DECL_SAVED_TREE (fndecl), fndecl, true= ); > (gdb) n > > Program received signal SIGSEGV, Segmentation fault. > size_binop_loc (loc=3D0, code=3DEXACT_DIV_EXPR, arg0=3D0x0, arg1=3D0xb757= 2680) > at ../../gcc-dev/gcc/fold-const.c:1414 > 1414 tree type =3D TREE_TYPE (arg0); > > > any idea ? > > thank you in advance > > Asma >=20=20=20=20 Hey Asma, the problem in your code is that you access the class/record in=20 create_operation() by a COMPONENT_REF although the class/record's layout=20 hasn't yet been built. To be clear, you call layout_type() which for=20 example sets the offset for each FIELD_DECL after create_operation().=20 Though, when the gimplifier tries to access the record, it requires the=20 offset of the FIELD_DECL to be available, but in your case, it is NULL_TREE. Since layout_type() for RECORD_TYPES doesn't work on TYPE_METHODS, you=20 could call layout_type() before processing the operations. By the way DECL_PACKED(myOperation2_tree) =3D false; does not work for FUNCTION_DECL, but only for FIELD_DECLs. Andi Hello, thank you very much Ian and Andi ;)=20 it works now (I call layout_type() before create_operation() as Andi sugge= st )=20 .=20 I could never guess it alone :D Asma