This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Help with TREEs
Hi Steve,
Adding this wee block into the deallocate code:
{
const char *message1 = "Attempt to deallocate an unallocated object";
const char *message2 = "OK";
tree errmsg, argh, check;
errmsg = gfc_create_var (pchar_type_node, "ERRMSG");
argh = gfc_create_var (pchar_type_node, "ARGH");
check = gfc_create_var (pchar_type_node, "CHECK");
tmp = fold_build2 (NE_EXPR, boolean_type_node, astat,
build_int_cst (TREE_TYPE (astat), 0));
gfc_add_modify (&block, errmsg,
gfc_build_addr_expr (pchar_type_node,
gfc_build_localized_cstring_const (message1)));
gfc_add_modify (&block, argh,
gfc_build_addr_expr (pchar_type_node,
gfc_build_localized_cstring_const (message2)));
tmp = fold_build3 (COND_EXPR, pchar_type_node, tmp, errmsg, argh);
gfc_add_modify (&block, check, tmp);
}
generates:
character(kind=1) * CHECK.5;
character(kind=1) * ARGH.4;
character(kind=1) * ERRMSG.3;
integer(kind=4) astat.2;
integer(kind=4) stat.1;
astat.2 = 0;
ERRMSG.3 = &"Attempt to deallocate an unallocated object"[1]{lb: 1 sz: 1};
ARGH.4 = &"OK"[1]{lb: 1 sz: 1};
CHECK.5 = astat.2 != 0 ? ERRMSG.3 : ARGH.4;
Which looks to be close to what you want., excepting that you will
have to make a call to memcpy, using gfc_build_memcpy_call, to
transfer the string, CHECK, to your variable.
Cheers
Paul