This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -Os seems to remove a variable necessary for my transformation


On Thu, May 3, 2012 at 3:30 PM, Matt Davis <mattdavis9@gmail.com> wrote:
> I have been fighting with a simple problem for the past few nights. ?In my
> GIMPLE pass I create a variable, an ssa name for that variable, and then assign
> it to the LHS of a call I build:
>
> ?call = gimple_build_call(fndecl, 0);
> ?decl = create_tmp_var(TREE_TYPE(TREE_TYPE(test_decode_fndecl)), "FOO");
> ?ssa ?= make_ssa_name(decl, call);
> ?gimple_set_lhs(call, ssa);
> ?gsi_insert_before(&gsi, call, GSI_SAME_STMT);
>
> I verify the GIMPLE and it looks proper:
>
> ?char * FOO.2;
> ?/* some gimple code */
> ?FOO.2_8 = fn();
> ?strcat(&mylocal, FOO.2_8);

Probably for the use stmt you did not call update_stmt.  You can check
in the debugger by debug_immediate_uses () which likely prints no use
for FOO.2_8

>
> However, when I build with -Os the GIMPLE looks like:
> ?char * FOO.2;
> ?/* some gimple code */
> ?fn();
> ?strcat(&mylocal, FOO.2_8);
>
> And the compiler segfaults in "ptr_deref_may_alias_decl_p" for 'ptr' FOO.2_8 and
> 'decl' mylocal arguments. ?The segfault occurs because TREE_TYPE(ptr) is NULL
> and calling POINTER_TYPE_P(TREE_TYPE(ptr)) dereferences a NULL.

That's what happens when an SSA name is released.

> After more debugging, it is eliminate_unnecessary_stmts() which tries to remove
> the 'FOO.2_8 = fn();' statement. ?In that routine, the LHS is considered "dead"
> and because of that the routine sets the LHS to NULL.

It's dead if it has no uses.

> So, I guess my question is, how can I force this stmt to hang around? ?I looked
> at eliminate_unnecessary_stmts, and do not see any specific flags I can set to
> the stmt to make 'em hang around, and I do not know what to do to make LHS
> appear not "dead." ?Even if I set 'ssa' TREE_USED and 'decl' as DECL_PRESERVE_P.

Well, that's not how SSA uses/defs work.

> Thanks for any information!
>
> -Matt


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]