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]

Query about the TREE_TYPE field


I was poking around attribs.c while trial running my tree-type-safety stuff, and it triggered something in decl_attributes() that seems fishy to me. It looks like it was part of the fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35315

decl_attributes() can be passed a tree node which is either decl or a type, but we get to this little snippet:

      if (spec->type_required && DECL_P (*anode))
        {
          anode = &TREE_TYPE (*anode);
          /* Allow ATTR_FLAG_TYPE_IN_PLACE for the type's naming decl.  */
          if (!(TREE_CODE (*anode) == TYPE_DECL
                && *anode == TYPE_NAME (TYPE_MAIN_VARIANT
                                        (TREE_TYPE (*anode)))))
            flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
        }

anode is changed to point to the TREE_TYPE of the original decl, and *then* checks if it is a TYPE_DECL... That doesnt seem right to me.. we can't have a TYPE_DECL as a TREE_TYPE can we?

is that code suppose to be checking is the original DECL is a TYPE_DECL rather than the TREE_TYPE?

I added an assert:
   anode = &TREE_TYPE (*anode);
+ gcc_assert (TREE_CODE (*anode) != TYPE_DECL);

and it never trips during bootstrap or a full testsuite run. I also tried the testcase in bugzilla and it compiles fine with the assert in place...

Maybe the assignment to anode should be after the if instead of in front of it?

Andrew








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