Hello,

On Mon, 23 Dec 2024, Robert Dubner wrote:

> > +static tree
> > +gg_get_larger_type(tree A, tree B)
> > +  {
> > +  tree larger = TREE_TYPE(B);
> > +  if( TYPE_SIZE(TREE_TYPE(A)) > TYPE_SIZE(TREE_TYPE(B)) )
> > +    {
> > +    larger = TREE_TYPE(A);
> >
> > that doesn't work - TYPE_SIZE is a pointer to a tree.  You can use
> > tree_int_cst_compare (TYPE_SIZE(TREE_TYPE(A)),
> > TYPE_SIZE(TREE_TYPE(B))) == 1 instead.
> 
> In any case, and given that gg_get_larger_type() is used by me in my code
> on variables I define, rather than on user code on variables the user
> defines, I believe it is doing what I need it to do.  For example, when I
> need to multiply tree A by tree B, I need them to both be of the same type
> in order to keep the TRUNC_DIV_EXPR from complaining that they aren't the
> same type.  So, I use gg_get_larger_type(A, B) to return the type of the
> one with the larger TYPE_SIZE, and then I cast both A and B to that type.

It may have been lost in the other (very interesting!) explanations about 
Cobol peculiarities, but no, the gg_get_larger_type() as written (and 
cited above) is _not_ doing what you want it to do.  TYPE_SIZE is a 
pointer, hence 'TYPE_SIZE(foo) > TYPE_SIZE(bar)' compares two pointers, 
not two numbers, and so what it returns is not the larger-sized type but 
simply the one whose size description was allocated at higher addresses in 
GCCs memory pool.  That may or may not coincide with those trees 
representing higher numbers.


Ciao,
Michael.

Reply via email to