public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
@ 2023-07-21 10:43 redi at gcc dot gnu.org
  2023-07-21 21:19 ` [Bug middle-end/110764] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-21 10:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110764
           Summary: [12/13/14 Regression] False positive -Warray-bounds
                    warning swapping std::thread::id
           Product: gcc
           Version: 12.3.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

#include <iostream>
#include <thread>
#include <vector>

void g(int n);

void g(int n) {
    std::cout << "consume: " << n << std::endl;
}

int main(void) {
    std::vector<std::thread> threads(1);
    // The compiler error comes from the two threads below.
    threads[0] = std::thread(g, 42);
    threads[1] = std::thread(g, 42);
    threads[0].join();
    threads[1].join();
    return (0);
}

Compiled with -Warray-bounds -O2 this gives a false positive:

In file included from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/exception_ptr.h:43,
                 from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/exception:168,
                 from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/ios:39,
                 from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/ostream:38,
                 from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/iostream:39,
                 from max.cc:1:
In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >,
std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&,
_Tp&) [with _Tp = thread::id]’,
    inlined from ‘void std::thread::swap(std::thread&)’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/std_thread.h:171:16,
    inlined from ‘std::thread& std::thread::operator=(std::thread&&)’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/std_thread.h:165:11,
    inlined from ‘int main()’ at max.cc:15:35:
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/move.h:205:7: warning: array
subscript 1 is outside array bounds of ‘std::thread [1]’ [-Warray-bounds]
  205 |       __a = _GLIBCXX_MOVE(__b);
      |       ^~~
In file included from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
                 from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/allocator.h:46,
                 from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/string:41,
                 from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/locale_classes.h:40,
                 from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/ios_base.h:41,
                 from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/ios:42:
In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const
void*) [with _Tp = std::thread]’,
    inlined from ‘static _Tp* std::allocator_traits<std::allocator<_CharT>
>::allocate(allocator_type&, size_type) [with _Tp = std::thread]’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/alloc_traits.h:464:28,
    inlined from ‘std::_Vector_base<_Tp, _Alloc>::pointer
std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp =
std::thread; _Alloc = std::allocator<std::thread>]’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/stl_vector.h:378:33,
    inlined from ‘void std::_Vector_base<_Tp,
_Alloc>::_M_create_storage(std::size_t) [with _Tp = std::thread; _Alloc =
std::allocator<std::thread>]’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/stl_vector.h:395:44,
    inlined from ‘std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t,
const allocator_type&) [with _Tp = std::thread; _Alloc =
std::allocator<std::thread>]’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/stl_vector.h:332:26,
    inlined from ‘std::vector<_Tp, _Alloc>::vector(size_type, const
allocator_type&) [with _Tp = std::thread; _Alloc =
std::allocator<std::thread>]’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/stl_vector.h:552:47,
    inlined from ‘int main()’ at max.cc:12:39:
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/new_allocator.h:137:55: note:
at offset 8 into object of size 8 allocated by ‘operator new’
  137 |         return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
      |                                                       ^


This started with r12-1992

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
@ 2023-07-21 21:19 ` pinskia at gcc dot gnu.org
  2023-07-21 21:21 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-21 21:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
hmm, this code seems like undefined code. If I change 1 to 2 as you are
accessing 2 elements via operator[], there is no warning ...

The warning seems correct and even says 1 bounds is above the array bounds of
[1].

The location of the warning seems off but I don't think the warning in this
case is false positive though.

Maybe it is due to the reduced testcase though.

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
  2023-07-21 21:19 ` [Bug middle-end/110764] " pinskia at gcc dot gnu.org
@ 2023-07-21 21:21 ` pinskia at gcc dot gnu.org
  2023-07-21 22:07 ` maxim.yegorushkin at gmail dot com
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-21 21:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So reading the original bug report, it is almost definitely an incorrectly
reduced testcase.

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
  2023-07-21 21:19 ` [Bug middle-end/110764] " pinskia at gcc dot gnu.org
  2023-07-21 21:21 ` pinskia at gcc dot gnu.org
@ 2023-07-21 22:07 ` maxim.yegorushkin at gmail dot com
  2023-07-21 22:11 ` maxim.yegorushkin at gmail dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: maxim.yegorushkin at gmail dot com @ 2023-07-21 22:07 UTC (permalink / raw)
  To: gcc-bugs

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

Maxim Egorushkin <maxim.yegorushkin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim.yegorushkin at gmail dot com

--- Comment #3 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> ---
The original correct reproduction:

#include <thread>
#include <vector>

void g(int);

void f() {
    std::vector<std::thread> threads(1);
    threads[0] = std::thread(g, 42); // Compiler error comes from this
statement.
    threads[0].join();
}

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-21 22:07 ` maxim.yegorushkin at gmail dot com
@ 2023-07-21 22:11 ` maxim.yegorushkin at gmail dot com
  2023-07-21 22:25 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: maxim.yegorushkin at gmail dot com @ 2023-07-21 22:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> ---
Full context: https://github.com/max0x7ba/atomic_queue/issues/55

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-07-21 22:11 ` maxim.yegorushkin at gmail dot com
@ 2023-07-21 22:25 ` pinskia at gcc dot gnu.org
  2023-07-21 22:34 ` maxim.yegorushkin at gmail dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-21 22:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Maxim Egorushkin from comment #3)
> The original correct reproduction:
> 
> #include <thread>
> #include <vector>
> 
> void g(int);
> 
> void f() {
>     std::vector<std::thread> threads(1);
>     threads[0] = std::thread(g, 42); // Compiler error comes from this
> statement.
>     threads[0].join();
> }

Can you provide the preprocessed source? Since I can't seem to reproduce it
with the above.

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-07-21 22:25 ` pinskia at gcc dot gnu.org
@ 2023-07-21 22:34 ` maxim.yegorushkin at gmail dot com
  2023-07-21 22:35 ` maxim.yegorushkin at gmail dot com
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: maxim.yegorushkin at gmail dot com @ 2023-07-21 22:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> ---
> Can you provide the preprocessed source? Since I can't seem to reproduce it with the above.

It should be compiled with "-pthread -std=gnu++14 -O3 -Wall -Wextra -Werror" to
trigger the warning/error.

But I don't have access to Debian gcc-13, which is the origin of this issue, to
be able to provide a preprocessed source.

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-07-21 22:34 ` maxim.yegorushkin at gmail dot com
@ 2023-07-21 22:35 ` maxim.yegorushkin at gmail dot com
  2023-07-21 22:38 ` maxim.yegorushkin at gmail dot com
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: maxim.yegorushkin at gmail dot com @ 2023-07-21 22:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> ---
> Can you provide the preprocessed source? Since I can't seem to reproduce it with the above.

It should be compiled with "-pthread -std=gnu++14 -O3 -Wall -Wextra -Werror" to
trigger the warning/error.

But I don't have access to Debian gcc-13, which is the origin of this issue, to
be able to provide a preprocessed source.

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-07-21 22:35 ` maxim.yegorushkin at gmail dot com
@ 2023-07-21 22:38 ` maxim.yegorushkin at gmail dot com
  2023-07-21 23:08 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: maxim.yegorushkin at gmail dot com @ 2023-07-21 22:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> ---
It was supposed to be one comment, but I kept clicking "save changes" button
because it provided no visual feedback that the comment was being posted.

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-07-21 22:38 ` maxim.yegorushkin at gmail dot com
@ 2023-07-21 23:08 ` redi at gcc dot gnu.org
  2023-10-17 10:27 ` rguenth at gcc dot gnu.org
  2024-03-07 23:28 ` law at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-21 23:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> So reading the original bug report, it is almost definitely an incorrectly
> reduced testcase.

Oops, yes, sorry for not noticing that before filling the bug

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2023-07-21 23:08 ` redi at gcc dot gnu.org
@ 2023-10-17 10:27 ` rguenth at gcc dot gnu.org
  2024-03-07 23:28 ` law at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-17 10:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.4

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

* [Bug middle-end/110764] [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
  2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2023-10-17 10:27 ` rguenth at gcc dot gnu.org
@ 2024-03-07 23:28 ` law at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-07 23:28 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org
           Priority|P3                          |P2

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

end of thread, other threads:[~2024-03-07 23:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21 10:43 [Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id redi at gcc dot gnu.org
2023-07-21 21:19 ` [Bug middle-end/110764] " pinskia at gcc dot gnu.org
2023-07-21 21:21 ` pinskia at gcc dot gnu.org
2023-07-21 22:07 ` maxim.yegorushkin at gmail dot com
2023-07-21 22:11 ` maxim.yegorushkin at gmail dot com
2023-07-21 22:25 ` pinskia at gcc dot gnu.org
2023-07-21 22:34 ` maxim.yegorushkin at gmail dot com
2023-07-21 22:35 ` maxim.yegorushkin at gmail dot com
2023-07-21 22:38 ` maxim.yegorushkin at gmail dot com
2023-07-21 23:08 ` redi at gcc dot gnu.org
2023-10-17 10:27 ` rguenth at gcc dot gnu.org
2024-03-07 23:28 ` law 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).