[proto-PATCH] Move some builtins conversions from convert.c to fold-const.c

Richard Guenther richard.guenther@gmail.com
Mon Feb 12 10:14:00 GMT 2007


On 2/12/07, Uros Bizjak <ubizjak@gmail.com> wrote:
> On 2/11/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
>
> > > BTW: Looking at ChangeLog-2004, I see that you are the author of
> > > (long)round -> lround transformation in convert.c, convert_to_integer()
> > > function. Following your lead, I have added other conversions, but my
> > > last patch to convert (int)logb -> ilogb was rejected by middle-end
> > > maintainers on the ground that these transformations belong to
> > > fold-const.c. I was trying to move these transformations to their better
> > > place but failed miserably... do you have any ideas on how to move this
> > > thing?
>
> > Err, I was just following the path beaten by those who came before me:
> > http://gcc.gnu.org/ml/gcc-patches/2002-11/msg00434.html
> > http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01451.html
> >
> > What exactly did you try that failed?  I'm guessing that the right place
> > for this would be in fold_unary where it handles convert exprs.  Peek into
> > the operand and if it's the right combination of type and builtin then do
> > the transformation. (?)
>
> Oh... looking a bit into my protopatch I found that (two!) arguments
> to new function were mixed somehow. After fixing this, patch magically
> started to work!
>
> I'm posting this non-patch for a comment here, if the path taken is
> OK. Although patch works OK (and passes a regression test), it is in
> fact only convert.c part stuffed into fold-const.c with some minimum
> "glue logic" aroud the call.

A few comments.  First, the code is/was in c-common.c because tree nodes
like long_integer_type_node are not guaranteed to be initialized by
all frontends.
Second - we should not issue errors or warnings from fold(), the

+  /* An INTEGER_TYPE cannot be incomplete, but an ENUMERAL_TYPE can
+     be.  Consider `enum E = { a, b = (enum E) 3 };'.  */
+  if (!COMPLETE_TYPE_P (type))
+    {
+      error ("conversion to incomplete type");
+      return error_mark_node;
+    }

needs to stay in convert () or properly put into the places we now
(early) fold this.
(One reason why I stopped doing the transition a long time ago...)

Otherwise this clearly looks like the way to go, we should, for the middle-ends
consistency maybe do the conversion on the grounds of TYPE_PRECISION and
TYPE_MODE only, not on the grounds of matching some magic foo_type_node.

Thanks,
Richard.



More information about the Gcc-patches mailing list