This is the mail archive of the gcc-patches@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: [ast-optimizer-branch]: Simplify STMT_EXPR's


On Thu, 2 May 2002, Sebastian Pop wrote:

> On Thu, May 02, 2002 at 11:56:48AM -0400, Daniel Berlin wrote:
> > > Maybe the error comes from the following ? Can you check ?
> > > 
> > > TREE_CHAIN (new_stmt) = TREE_CHAIN (temp);
> > > TREE_CHAIN (temp) = new_stmt;
> > 
> > Doesn't this turn:
> > 
> > 
> > temp
> > stmt_2
> > 
> > into
> > 
> > temp
> > new_stmt
> > stmt_2
> > 
> > ?
> > 
> Yes it does, but, ...
> 
> Suppose that temp points to a SCOPE_STMT.
It never *should*, from what i understand.
It should always be an EXPR_STMT.

> Then you declare some variables.
> Then you rechain against temp.
> 
> SCOPE_STMT  <- temp
> EXPR_STMT   <- stmt_2
> 
> then you declare some variables : 
> SCOPE_STMT  <- temp
> DECL_STMT
> DECL_STMT
> EXPR_STMT   <- stmt_2
> 
> then you rechain :
> 
> SCOPE_STMT  <- temp
> *_STMT      <- new_stmt
> EXPR_STMT   <- stmt_2
> 
> Result : you've lost 2 DECL_STMT.
> 
> Maybe you can try the following :
> 
> if (TREE_CODE (temp) == SCOPE_STMT)
>   temp = tree_last_decl (temp);
> TREE_CHAIN (new_stmt) = TREE_CHAIN (temp);
> TREE_CHAIN (temp) = new_stmt;
> ...

Doesn't help.

It only doesn't work on the following type of horrendous construct:

for (a = lookup_attribute (*(
{
  union tree_node * __t = *(
  {
    union tree_node * __t = a2;
    if (*__t.common.code != 2)
      tree_check_failed (__t, 2, "../../gcc/tree.c", 2695, 
"merge_attributes");
    __t;
  }
  ).list.purpose;
  if (*__t.common.code != 1)
    tree_check_failed (__t, 1, "../../gcc/tree.c", 2695, 
"merge_attributes");
  __t;
}
).identifier.id.str, attributes); a != 0; a = lookup_attribute (*(
{
  union tree_node * __t = *(
  {
    union tree_node * __t = a2;
    if (*__t.common.code != 2)
      tree_check_failed (__t, 2, "../../gcc/tree.c", 2698, 
"merge_attributes");
    __t;
  }
  ).list.purpose;
  if (*__t.common.code != 1)
    tree_check_failed (__t, 1, "../../gcc/tree.c", 2698, 
"merge_attributes");
  __t;
}
).identifier.id.str, *a.common.chain))


(Yes, that's just the for expression.)


The first portion gets transformed into:
          union tree_node * a;
                  {
                    union tree_node * __t = *(
                    {
                      union tree_node * __t = a2;
                      if (*__t.common.code != 2)
                        tree_check_failed (__t, 2, "../../gcc/tree.c", 
2695, "merge_attributes");
                      __t;
                    }
                    ).list.purpose;
                    T.2721 = *__t.common.code;
                    T.2722 = T.2721 != 1;
                    if (T.2722 != 0)
                      {
                        T.2715 = "../../gcc/tree.c";
                        T.2716 = T.2715;
                        T.2717 = T.2716;
                        T.2718 = "merge_attributes";
                        T.2719 = T.2718;
                        T.2720 = T.2719;
                        tree_check_failed (__t, 1, T.2717, 2695, T.2720);
                      }
                    T.2723 = __t;
                  }
                  T.2724 = *T.2723.identifier.id.str;
                  a = lookup_attribute (T.2724, attributes);

(We don't try to simplify the initialization of __t here, because it's a 
readonly variable. That's why it's still a statement expr).


It's aborting trying to expand

T.2721 = *__t.common.code;

For some reason, the __t in that statement doesn't have RTL, associated 
with it (which is why it goes to make some), while I think the expression 
right above it should have just done that.


The above was printed with your pretty printer patch, as well as your 
suggestion just in case temp happens to be a scope_stmt somehow, 
incorporated.

 > 
> 
> Seb/
> 


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