This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Help with TREEs
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org
- Date: Fri, 28 Nov 2008 18:13:28 -0800
- Subject: Help with TREEs
Seeking some input on trans-*.c.
I have the program
program a
character(len=80) :: err
integer, allocatable :: i(:)
err = 'No error'
allocate(i(4))
deallocate(i, errmsg=err)
print *, err ! Should print 'No error'
end program a
The frontend parsing works fine, but gfc_trans_deallocate in
trans-stmt.c is giving me fits. I currently have
if (code->expr)
{
/* Assign the value to the status variable. */
if (code->expr->ts.type == BT_INTEGER)
{
/* removed to get to my question. */
}
/* Assign an errmsg to the ERRMSG variable if astat is nonzero. sgk */
else
{
const char *message1 = "Attempt to deallocate an unallocated object";
const char *message2 = "OK";
tree errmsg, argh;
gfc_init_se (&se, NULL);
gfc_conv_expr_lhs (&se, code->expr);
tmp = fold_build2 (NE_EXPR, boolean_type_node, astat,
build_int_cst (TREE_TYPE (astat), 0));
errmsg = gfc_build_localized_cstring_const (message1);
argh = gfc_build_localized_cstring_const (message2);
tmp = build3_v (COND_EXPR, tmp, errmsg, argh);
gfc_add_modify (&block, se.expr, tmp);
}
}
-fdump-tree-original shows
a ()
{
character(kind=1) err[1:80];
...
{
integer(kind=4) astat.2;
integer(kind=4) stat.1;
astat.2 = 0;
if (i.data == 0B)
{
*&stat.1 = 1;
}
else
{
__builtin_free (i.data);
*&stat.1 = 0;
}
i.data = 0B;
astat.2 = astat.2 + stat.1;
err = if (astat.2 != 0)
{
"Attempt to deallocate an unallocated object"
}
else
{
"OK"
};
}
This is clearly wrong. What I need is the equivalent of
if (astat.2 != 0)
{
strncpy(err, message1, strlen(err));
}
I'll keep pecking away, but pointers would be appreciated.
--
Steve