This is the mail archive of the gcc@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: Comparing tree types


Hi,

On Mon, Nov 03, 2014 at 03:12:10AM +0530, Vini Kanvar wrote:
> I am trying to compare the tree declarations of the lhs and the rhs of
> the assignment statement in the following program.
> 
> struct node {
>         struct node * next;
> };
> struct node ** obj1, obj2;
> obj1 = &obj2.next;		// lhs is obj1, rhs is obj2.next

RHS should be &obj2.next, note the &.  I suppose that is why you are
getting a non-pointer type when inspecting TREE_TYPE (obj2.next_tree),
because according to the dumps below, you are missing an ADDR_EXPR
somewhere.

Please note that when comparing types, you should probably use a
designated function to do that.  If you work at GIMPLE level, such
functions are types_compatible_p or useless_type_conversion_p, I do
not remember now what they are at GENERIC stage.

> 
> -----------
> Let us call the following tree declaration of the lhs as "obj1_tree".
> -------------
>  <var_decl 0x405cc180 obj1
>     type <pointer_type 0x405c5ea0
>         type <pointer_type 0x405c5f00 type <record_type 0x405c5f60 node>
>             unsigned SI
>             size <integer_cst 0x40511578 constant 32>
>             unit size <integer_cst 0x40511594 constant 4>
>             align 32 symtab 0 alias set -1 canonical type 0x405cc000
>             pointer_to_this <pointer_type 0x405c5ea0>>
>         unsigned SI
>         size <integer_cst 0x40511578 constant 32>
>         unit size <integer_cst 0x40511594 constant 4>
>         align 32 symtab 0 alias set -1 canonical type 0x405c5ea0>
>     used unsigned SI file structstruct2.c line 8 col 17
>     size <integer_cst 0x40511578 type <integer_type 0x40521060
> bitsizetype> constant 32>
>     unit size <integer_cst 0x40511594 type <integer_type 0x40521000
> sizetype> constant 4>
>     align 32 context <function_decl 0x405c9080 main> chain <var_decl
> 0x405cc1e0 obj2>>
> 
> -------------
> Let us call the following tree declaration of the rhs as
> "obj2.next_tree"
> -------------
>  <field_decl 0x4051f0b8 next
>     type <pointer_type 0x405cc000
>         type <record_type 0x405c5f60 node SI
>             size <integer_cst 0x40511578 constant 32>
>             unit size <integer_cst 0x40511594 constant 4>
>             align 32 symtab 0 alias set -1 canonical type 0x405c5f60
> fields <field_decl 0x4051f0b8 next> context <translation_unit_decl
> 0x40526804 D.2319>
>             pointer_to_this <pointer_type 0x405c5f00> chain <type_decl
> 0x40526870 node>>
>         unsigned SI
>         size <integer_cst 0x40511578 constant 32>
>         unit size <integer_cst 0x40511594 constant 4>
>         align 32 symtab 0 alias set -1 canonical type 0x405cc000
>         pointer_to_this <pointer_type 0x405cc060>>
>     used unsigned nonlocal SI file structstruct2.c line 3 col 16
>     size <integer_cst 0x40511578 type <integer_type 0x40521060
> bitsizetype> constant 32>
>     unit size <integer_cst 0x40511594 type <integer_type 0x40521000
> sizetype> constant 4>
>     align 32 offset_align 128
>     offset <integer_cst 0x405115b0 type <integer_type 0x40521000
> sizetype> constant 0>
>     bit offset <integer_cst 0x4051163c type <integer_type 0x40521060
> bitsizetype> constant 0> context <record_type 0x405c5f60 node> chain
> <type_decl 0x405268dc node>>
> -------------
> 
> Please note from the above tree declarations that 
> Type1 = TREE_TYPE (TREE_TYPE (obj1_tree)) = 0x405c5f00
> Type2 = TREE_TYPE (obj2.next_tree) = 0x405cc000
> Type3 = TYPE_POINTER_TO (TREE_TYPE (TREE_TYPE (obj2.next_tree))) =
> 0x405c5f00
> 
> I was expecting Type1 and Type2 to be equal because obj1=&obj2.next.
> However, in this case, we see that Type1 and Type3 are equal. Please
> explain this.
> 
> Also, what is the meaning of "pointer_to_this" in the tree declarations?

I have not double checked but I suppose that is a simple mechanism of
caching so that we do not re-create the same type multiple times.

HTH

Martin


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