public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized
@ 2022-11-18 13:31 alvinhochun at gmail dot com
  2022-11-18 20:01 ` [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0 pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: alvinhochun at gmail dot com @ 2022-11-18 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107751
           Summary: [11/12 regression] False positive
                    -Wmaybe-uninitialized
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alvinhochun at gmail dot com
  Target Milestone: ---

This test case produces false-positive -Wmaybe-uninitialized warnings:

===
template <class T1, class T2>
bool std_equal(T1* a1, T1* a2, T2* b1);

template <class T1, class T2>
bool std_equal(T1* a1, T1* a2, T2* b1, T2* b2);

template <class T1, class T2>
void f() {
    int a[3] = {1, 2, 3};
    T1* x    = a;
    T2* y    = a;
    std_equal(x, x + 3, y);
    std_equal(y, y + 3, x);
    std_equal(x, x + 3, y, y + 3);
    std_equal(y, y + 3, x, x + 3);
}

int main(int, char**) {
    f<int, int>();
    f<int, const int>();
    f<int, volatile int>();
    f<int, const volatile int>();
    f<const int, const int>();
    f<const int, volatile int>();
    f<const int, const volatile int>();
    f<volatile int, volatile int>();
    f<volatile int, const volatile int>();
    f<const volatile int, const volatile int>();
    return 0;
}
===

Output:

===
<source>: In function 'void f() [with T1 = const int; T2 = const int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const int*' to 'bool std_equal(T1*,
T1*, T2*) [with T1 = const int; T2 = const int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
<source>: In function 'void f() [with T1 = const int; T2 = volatile int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const int*' to 'bool std_equal(T1*,
T1*, T2*) [with T1 = const int; T2 = volatile int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
<source>: In function 'void f() [with T1 = const int; T2 = const volatile
int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const int*' to 'bool std_equal(T1*,
T1*, T2*) [with T1 = const int; T2 = const volatile int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
<source>: In function 'void f() [with T1 = const volatile int; T2 = const
volatile int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const volatile int*' to 'bool
std_equal(T1*, T1*, T2*) [with T1 = const volatile int; T2 = const volatile
int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
===

Compiler Explorer: https://godbolt.org/z/KsM6herr9

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

* [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0
  2022-11-18 13:31 [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized alvinhochun at gmail dot com
@ 2022-11-18 20:01 ` pinskia at gcc dot gnu.org
  2022-11-18 20:03 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-18 20:01 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.4
   Last reconfirmed|                            |2022-11-18
            Summary|[11/12 regression] False    |[11/12/13 regression] False
                   |positive                    |positive
                   |-Wmaybe-uninitialized at    |-Wmaybe-uninitialized at
                   |-O0                         |-O0
     Ever confirmed|0                           |1
      Known to fail|                            |11.1.0, 12.2.0, 13.0
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |10.4.0
           Keywords|                            |needs-bisection

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0
  2022-11-18 13:31 [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized alvinhochun at gmail dot com
  2022-11-18 20:01 ` [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0 pinskia at gcc dot gnu.org
@ 2022-11-18 20:03 ` pinskia at gcc dot gnu.org
  2022-11-18 20:06 ` [Bug tree-optimization/107751] " mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-18 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase (removes the templates, also now able to compile as C):
typedef const int T1;
typedef const int T2;
void std_equal(T1* a1, T1* a2, T2* b1);
void f() {
    int a[3] = {1, 2, 3};
    T1* x    = a;
    T2* y    = a;
    std_equal(x, x+3, y);
}

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

* [Bug tree-optimization/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0
  2022-11-18 13:31 [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized alvinhochun at gmail dot com
  2022-11-18 20:01 ` [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0 pinskia at gcc dot gnu.org
  2022-11-18 20:03 ` pinskia at gcc dot gnu.org
@ 2022-11-18 20:06 ` mpolacek at gcc dot gnu.org
  2022-12-20 15:56 ` rguenth at gcc dot gnu.org
  2023-05-29 10:07 ` [Bug tree-optimization/107751] [11/12/13/14 " jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-11-18 20:06 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r11-959-gb825a22890740f:

commit b825a22890740f341eae566af27e18e528cd29a7
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Jun 4 16:06:10 2020 -0600

    Implement a solution for PR middle-end/10138 and PR middle-end/95136.

    PR middle-end/10138 - warn for uninitialized arrays passed as const
arguments
    PR middle-end/95136 - missing -Wuninitialized on an array access with a
variable offset

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

* [Bug tree-optimization/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0
  2022-11-18 13:31 [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized alvinhochun at gmail dot com
                   ` (2 preceding siblings ...)
  2022-11-18 20:06 ` [Bug tree-optimization/107751] " mpolacek at gcc dot gnu.org
@ 2022-12-20 15:56 ` rguenth at gcc dot gnu.org
  2023-05-29 10:07 ` [Bug tree-optimization/107751] [11/12/13/14 " jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-20 15:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Reduced testcase (removes the templates, also now able to compile as C):
> typedef const int T1;
> typedef const int T2;
> void std_equal(T1* a1, T1* a2, T2* b1);
> void f() {
>     int a[3] = {1, 2, 3};
>     T1* x    = a;
>     T2* y    = a;
>     std_equal(x, x+3, y);
> }

It's also odd we diagnose x + 3 but not x + 2.  We're using
ao_ref_init_from_ptr_and_size but that's not a good measure,
esp. for

  /* Do not warn if the access is zero size or if it's fully outside
     the object.  */
  poly_int64 decl_size;
  if (known_size_p (ref.size)
      && known_eq (ref.max_size, ref.size)
      && (known_eq (ref.size, 0)
          || known_le (ref.offset + ref.size, 0)))
    return NULL_TREE;

also given that this function doesn't do a good job at gettting at &a for
the IL at -O0 which is

  <bb 2> :
  a[0] = 1;
  a[1] = 2;
  a[2] = 3;
  x_6 = &a;
  y_7 = &a;
  _1 = x_6 + 8;
  std_equal (x_6, _1, y_7);

note that a function receiving x + O can adjust this pointer before reading
from it so using [x+O, +INF] as access range to find initialization isn't
the best thing to do.

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

* [Bug tree-optimization/107751] [11/12/13/14 regression] False positive -Wmaybe-uninitialized at -O0
  2022-11-18 13:31 [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized alvinhochun at gmail dot com
                   ` (3 preceding siblings ...)
  2022-12-20 15:56 ` rguenth at gcc dot gnu.org
@ 2023-05-29 10:07 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-29 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.4                        |11.5

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.4 is being released, retargeting bugs to GCC 11.5.

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

end of thread, other threads:[~2023-05-29 10:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 13:31 [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized alvinhochun at gmail dot com
2022-11-18 20:01 ` [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0 pinskia at gcc dot gnu.org
2022-11-18 20:03 ` pinskia at gcc dot gnu.org
2022-11-18 20:06 ` [Bug tree-optimization/107751] " mpolacek at gcc dot gnu.org
2022-12-20 15:56 ` rguenth at gcc dot gnu.org
2023-05-29 10:07 ` [Bug tree-optimization/107751] [11/12/13/14 " jakub 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).