public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106446] New: -Warray-bounds false positive on downcast under condition
@ 2022-07-26 11:10 coillol at yandex dot ru
  2022-07-27  8:27 ` [Bug tree-optimization/106446] " marxin at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: coillol at yandex dot ru @ 2022-07-26 11:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106446
           Summary: -Warray-bounds false positive on downcast under
                    condition
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: coillol at yandex dot ru
  Target Milestone: ---

Minimized example:

---
struct B { int x = 1; };

struct D1 : B {};

struct Data {
  int val = 666;
};

struct D2 : Data, B {
  static bool is_me(const B &b);
};

static int bar(const B &b) {
  if (D2::is_me(b))
    return static_cast<const D2 &>(b).val;
  return 777;
};

int foo() {
  return bar(D1{});
}
---

Compiling using `g++
(Compiler-Explorer-Build-gcc-789c4b9bb015c361bc1a6adfcd0abadce555e562-binutils-2.38)
13.0.0 20220725 (experimental)` with `-O2 -Wall` there is a warning:

--
In function 'int bar(const B&)',
    inlined from 'int foo()' at <source>:20:13:
<source>:15:39: warning: array subscript 0 is outside array bounds of 'D1 [1]'
[-Warray-bounds]
   15 |     return static_cast<const D2 &>(b).val;
      |                                       ^~~
<source>: In function 'int foo()':
<source>:20:17: note: at offset -4 into object '<anonymous>' of size 4
   20 |   return bar(D1{});
      |    
--

Such behavior is observed with from gcc >= 10.1. Less minimized example --
https://godbolt.org/z/vb786jhfn -- can be reproduced only with gcc >= 12.1.

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

* [Bug tree-optimization/106446] -Warray-bounds false positive on downcast under condition
  2022-07-26 11:10 [Bug tree-optimization/106446] New: -Warray-bounds false positive on downcast under condition coillol at yandex dot ru
@ 2022-07-27  8:27 ` marxin at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-07-27  8:27 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-07-27
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r10-4300-g49fb45c81f4ac068.

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

end of thread, other threads:[~2022-07-27  8:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-26 11:10 [Bug tree-optimization/106446] New: -Warray-bounds false positive on downcast under condition coillol at yandex dot ru
2022-07-27  8:27 ` [Bug tree-optimization/106446] " marxin 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).