public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
@ 2021-07-08  6:53 tnfchris at gcc dot gnu.org
  2021-07-08  7:42 ` [Bug bootstrap/101372] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2021-07-08  6:53 UTC (permalink / raw)
  To: gcc-bugs

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?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
@ 2021-07-08  7:42 ` rguenth at gcc dot gnu.org
  2021-07-08  7:50 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-08  7:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
  2021-07-08  7:42 ` [Bug bootstrap/101372] " rguenth at gcc dot gnu.org
@ 2021-07-08  7:50 ` rguenth at gcc dot gnu.org
  2021-07-08  9:30 ` tnfchris at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-08  7:50 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Probably similar to PR101374 - try reverting r12-2132

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
  2021-07-08  7:42 ` [Bug bootstrap/101372] " rguenth at gcc dot gnu.org
  2021-07-08  7:50 ` rguenth at gcc dot gnu.org
@ 2021-07-08  9:30 ` tnfchris at gcc dot gnu.org
  2021-07-08 10:46 ` schwab@linux-m68k.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2021-07-08  9:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
yes revering r12-2132 does indeed fix it.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-07-08  9:30 ` tnfchris at gcc dot gnu.org
@ 2021-07-08 10:46 ` schwab@linux-m68k.org
  2021-07-08 19:11 ` msebor at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: schwab@linux-m68k.org @ 2021-07-08 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Andreas Schwab <schwab@linux-m68k.org> ---
It's all the same.

*** This bug has been marked as a duplicate of bug 101374 ***

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-07-08 10:46 ` schwab@linux-m68k.org
@ 2021-07-08 19:11 ` msebor at gcc dot gnu.org
  2021-07-08 22:35 ` segher at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-08 19:11 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
         Resolution|DUPLICATE                   |---
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2021-07-08
             Status|RESOLVED                    |ASSIGNED

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
I have fixed these instances in r12-2171 but I don't think the root cause is
the same as the warnings noted in pr101374.  Let me use this bug to track the
analysis and the right fix in case the suppression is not appropriate.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-07-08 19:11 ` msebor at gcc dot gnu.org
@ 2021-07-08 22:35 ` segher at gcc dot gnu.org
  2021-07-08 22:40 ` cvs-commit at gcc dot gnu.org
  2021-07-08 22:42 ` [Bug bootstrap/101372] [12 Regression] -Warray-bounds in gcc/cp/module.cc causing bootstrap failure msebor at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: segher at gcc dot gnu.org @ 2021-07-08 22:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Segher Boessenkool <segher at gcc dot gnu.org> ---
On powerpc64-linux the failure is

In file included from /home/segher/src/gcc/gcc/c-family/c-common.h:26,
                 from /home/segher/src/gcc/gcc/cp/cp-tree.h:40,
                 from /home/segher/src/gcc/gcc/cp/module.cc:209:
In function 'tree_node* identifier(const cpp_hashnode*)',
    inlined from 'bool module_state::read_macro_maps()' at
/home/segher/src/gcc/gcc/cp/module.cc:16305:10:
/home/segher/src/gcc/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)))
      |                                                          ^
/home/segher/src/gcc/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 /home/segher/src/gcc/gcc/tree.h:23,
                 from /home/segher/src/gcc/gcc/c-family/c-common.h:26,
                 from /home/segher/src/gcc/gcc/cp/cp-tree.h:40,
                 from /home/segher/src/gcc/gcc/cp/module.cc:209:
/home/segher/src/gcc/gcc/tree-core.h: In member function 'bool
module_state::read_macro_maps()':
/home/segher/src/gcc/gcc/tree-core.h:1445:24: note: at offset -24 into object
'tree_identifier::id' of size 16
 1445 |   struct ht_identifier id;
      |                        ^~
In file included from /home/segher/src/gcc/gcc/c-family/c-common.h:26,
                 from /home/segher/src/gcc/gcc/cp/cp-tree.h:40,
                 from /home/segher/src/gcc/gcc/cp/module.cc:209:
In function 'tree_node* identifier(const cpp_hashnode*)',
    inlined from 'void module_state::install_macros()' at
/home/segher/src/gcc/gcc/cp/module.cc:16915:10:
/home/segher/src/gcc/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)))
      |                                                          ^
/home/segher/src/gcc/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 /home/segher/src/gcc/gcc/tree.h:23,
                 from /home/segher/src/gcc/gcc/c-family/c-common.h:26,
                 from /home/segher/src/gcc/gcc/cp/cp-tree.h:40,
                 from /home/segher/src/gcc/gcc/cp/module.cc:209:
/home/segher/src/gcc/gcc/tree-core.h: In member function 'void
module_state::install_macros()':
/home/segher/src/gcc/gcc/tree-core.h:1445:24: note: at offset -24 into object
'tree_identifier::id' of size 16
 1445 |   struct ht_identifier id;
      |                        ^~
In file included from /home/segher/src/gcc/gcc/c-family/c-common.h:26,
                 from /home/segher/src/gcc/gcc/cp/cp-tree.h:40,
                 from /home/segher/src/gcc/gcc/cp/module.cc:209:
In function 'tree_node* identifier(const cpp_hashnode*)',
    inlined from 'void module_state::install_macros()' at
/home/segher/src/gcc/gcc/cp/module.cc:16933:16:
/home/segher/src/gcc/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)))
      |                                                          ^
/home/segher/src/gcc/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 /home/segher/src/gcc/gcc/tree.h:23,
                 from /home/segher/src/gcc/gcc/c-family/c-common.h:26,
                 from /home/segher/src/gcc/gcc/cp/cp-tree.h:40,
                 from /home/segher/src/gcc/gcc/cp/module.cc:209:
/home/segher/src/gcc/gcc/tree-core.h: In member function 'void
module_state::install_macros()':
/home/segher/src/gcc/gcc/tree-core.h:1445:24: note: at offset -24 into object
'tree_identifier::id' of size 16
 1445 |   struct ht_identifier id;
      |                        ^~
cc1plus: all warnings being treated as errors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] Bootstrap failure compiling gcc/cp/module.cc
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-07-08 22:35 ` segher at gcc dot gnu.org
@ 2021-07-08 22:40 ` cvs-commit at gcc dot gnu.org
  2021-07-08 22:42 ` [Bug bootstrap/101372] [12 Regression] -Warray-bounds in gcc/cp/module.cc causing bootstrap failure msebor at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-08 22:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:79d3378c7d73814442eb468c562ab8aa572f9c43

commit r12-2178-g79d3378c7d73814442eb468c562ab8aa572f9c43
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Jul 8 16:36:15 2021 -0600

    Move warning suppression to the ultimate callee.

    Resolves:
    PR bootstrap/101372 - -Warray-bounds in gcc/cp/module.cc causing bootstrap
failure

    gcc/cp/ChangeLog:

            PR bootstrap/101372
            * module.cc (identifier): Suppress warning.
            (module_state::read_macro_maps): Remove warning suppression.
            (module_state::install_macros): Ditto.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug bootstrap/101372] [12 Regression] -Warray-bounds in gcc/cp/module.cc causing bootstrap failure
  2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-07-08 22:40 ` cvs-commit at gcc dot gnu.org
@ 2021-07-08 22:42 ` msebor at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-08 22:42 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
            Summary|[12 Regression] Bootstrap   |[12 Regression]
                   |failure compiling           |-Warray-bounds in
                   |gcc/cp/module.cc            |gcc/cp/module.cc causing
                   |                            |bootstrap failure
             Blocks|                            |56456
         Resolution|---                         |FIXED

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning triggers here because the code accesses an object using an address
computed by adding a negative constant to the address of a member subobject. 
The arithmetic result is a pointer to another object but logically (in C) the
computation is invalid.

The preprocessed code for the identifier() function does this:

static inline tree identifier (const cpp_hashnode *node)
{
  return ((tree) ((char *) ((&(const_cast<cpp_hashnode *> (node))->ident)) -
sizeof (struct tree_common)));
}

That's strictly incorrect (undefined) and the warning points it out.  The IL
below shows where the problem is detected:

void module_state::install_macros (struct module_state * const this)
{
  ...
  union tree_node * _95;
  ...
  <bb 11> [local count: 710990510]:
  _95 = get_identifier_with_length (_93, len.30_94);
  _96 = &MEM[(struct tree_identifier *)_95].id;             <<< subobject

  <bb 12> [local count: 1014686043]:
  # _97 = PHI <0B(10), _96(11)>
  len ={v} {CLOBBER};
  _43 = get_macro_imports (_97);
  _45 = bytes_in::u (sec_32);
  flags_46 = _45 & 3;
  if (flags_46 == 0)
    goto <bb 13>; [50.00%]
  else
    goto <bb 14>; [50.00%]

  <bb 18> [local count: 479439156]:
  _47 = &MEM <struct ht_identifier> [(void *)_97 + -24B];   <<< -Warray-bounds

Pointer arithmetic needs to be bounded to the innermost object (or subobject)
the pointer was derived from.  The warning enforces it to prevent accessing the
wrong member by accident.  The following alternate way code the same function
avoids the warning:

static inline tree identifier (const cpp_hashnode *node)
{
  char *p = (char *)const_cast<cpp_hashnode *> (node);
  p += __builtin_offsetof (cpp_hashnode, ident);
  p -= sizeof (struct tree_common);
  return (tree)p;
}

But rewriting it this way using the HT_XXX macros would be cumbersome so it
might be better to suppress the warning.  I have committed r12-2178 moving the
suppression from the callers to the identifier() function.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-07-08 22:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08  6:53 [Bug bootstrap/101372] New: [12 Regression] Bootstrap failure compiling gcc/cp/module.cc tnfchris at gcc dot gnu.org
2021-07-08  7:42 ` [Bug bootstrap/101372] " rguenth at gcc dot gnu.org
2021-07-08  7:50 ` rguenth at gcc dot gnu.org
2021-07-08  9:30 ` tnfchris at gcc dot gnu.org
2021-07-08 10:46 ` schwab@linux-m68k.org
2021-07-08 19:11 ` msebor at gcc dot gnu.org
2021-07-08 22:35 ` segher at gcc dot gnu.org
2021-07-08 22:40 ` cvs-commit at gcc dot gnu.org
2021-07-08 22:42 ` [Bug bootstrap/101372] [12 Regression] -Warray-bounds in gcc/cp/module.cc causing bootstrap failure msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).