https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101372

            Bug ID: 101372
           Summary: [12 Regression] Bootstrap failure compiling
                    gcc/cp/module.cc
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: bootstrap
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tnfchris at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64-*

At the current HEAD (g:852b11da11a181df517c0348df044354ff0656d6) the bootstrap
is broken with a number of -Werror failures such as

ibiberty/libiberty.a ../libdecnumber/libdecnumber.a
In file included from ../../gcc-fsf/gcc/c-family/c-common.h:26,
                 from ../../gcc-fsf/gcc/cp/cp-tree.h:40,
                 from ../../gcc-fsf/gcc/cp/module.cc:209:
In function ‘tree_node* identifier(const cpp_hashnode*)’,
    inlined from ‘bool module_state::read_macro_maps()’ at
../../gcc-fsf/gcc/cp/module.cc:16305:10:
../../gcc-fsf/gcc/tree.h:1089:58: error: array subscript -1 is outside array
bounds of ‘cpp_hashnode [288230376151711743]’ [-Werror=array-bounds]
 1089 |   ((tree) ((char *) (NODE) - sizeof (struct tree_common)))
      |                                                          ^
../../gcc-fsf/gcc/cp/module.cc:277:10: note: in expansion of macro
‘HT_IDENT_TO_GCC_IDENT’
  277 |   return HT_IDENT_TO_GCC_IDENT (HT_NODE (const_cast<cpp_hashnode *>
(node)));
      |          ^~~~~~~~~~~~~~~~~~~~~
In file included from ../../gcc-fsf/gcc/tree.h:23,
                 from ../../gcc-fsf/gcc/c-family/c-common.h:26,
                 from ../../gcc-fsf/gcc/cp/cp-tree.h:40,
                 from ../../gcc-fsf/gcc/cp/module.cc:209:
../../gcc-fsf/gcc/tree-core.h: In member function ‘bool
module_state::read_macro_maps()’:
../../gcc-fsf/gcc/tree-core.h:1445:24: note: at offset -24 into object
‘tree_identifier::id’ of size 16
 1445 |   struct ht_identifier id;
      |                        ^~

The macro defined in gcc/tree.h:1089 

#define HT_IDENT_TO_GCC_IDENT(NODE) \
  ((tree) ((char *) (NODE) - sizeof (struct tree_common)))

does no null check on NODE which can then result in a value of -1 for the
resulting size_t.

I can't really see what caused this to be triggered, don't see a recent commit
that touched this (from a quick search).

Should a simple null check be added here?

Reply via email to