This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
-Os seems to remove a variable necessary for my transformation
- From: Matt Davis <mattdavis9 at gmail dot com>
- To: gcc at gnu dot org
- Date: Thu, 3 May 2012 23:30:43 +1000
- Subject: -Os seems to remove a variable necessary for my transformation
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);
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.
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.
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.
Thanks for any information!
-Matt