* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
@ 2022-04-13 11:31 ` redi at gcc dot gnu.org
2022-04-13 11:33 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-13 11:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-04-13
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
2022-04-13 11:31 ` [Bug libstdc++/105258] " redi at gcc dot gnu.org
@ 2022-04-13 11:33 ` redi at gcc dot gnu.org
2022-04-13 12:11 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-13 11:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The simplest solution would be to just use std::allocator<T> which already does
the right thing, but that would break if there is a program-defined
specialization of std::allocator<T>.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
2022-04-13 11:31 ` [Bug libstdc++/105258] " redi at gcc dot gnu.org
2022-04-13 11:33 ` redi at gcc dot gnu.org
@ 2022-04-13 12:11 ` redi at gcc dot gnu.org
2022-04-13 12:11 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-13 12:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Created attachment 52799
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52799&action=edit
Patch to support extended alignment
This needs a testsuite addition, and should probably wait for GCC 13 now.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (2 preceding siblings ...)
2022-04-13 12:11 ` redi at gcc dot gnu.org
@ 2022-04-13 12:11 ` redi at gcc dot gnu.org
2023-04-26 6:55 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-13 12:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (3 preceding siblings ...)
2022-04-13 12:11 ` redi at gcc dot gnu.org
@ 2023-04-26 6:55 ` rguenth at gcc dot gnu.org
2023-07-27 9:22 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-26 6:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.0 |13.2
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.1 is being released, retargeting bugs to GCC 13.2.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (4 preceding siblings ...)
2023-04-26 6:55 ` rguenth at gcc dot gnu.org
@ 2023-07-27 9:22 ` rguenth at gcc dot gnu.org
2024-05-21 9:11 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27 9:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.2 |13.3
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (5 preceding siblings ...)
2023-07-27 9:22 ` rguenth at gcc dot gnu.org
@ 2024-05-21 9:11 ` jakub at gcc dot gnu.org
2024-05-31 7:39 ` Marco.Porsch at intenta dot de
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21 9:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.3 |13.4
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.3 is being released, retargeting bugs to GCC 13.4.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (6 preceding siblings ...)
2024-05-21 9:11 ` jakub at gcc dot gnu.org
@ 2024-05-31 7:39 ` Marco.Porsch at intenta dot de
2024-05-31 9:58 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Marco.Porsch at intenta dot de @ 2024-05-31 7:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Marco Porsch <Marco.Porsch at intenta dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Marco.Porsch at intenta dot de
--- Comment #6 from Marco Porsch <Marco.Porsch at intenta dot de> ---
When compiled to ARM NEON vector operations, which have strict alignment
requirements, this issue causes a kernel alignment trap and SIGBUS.
See godbolt [1] for an example using Eigen matrix library. Compiled with clang,
the instruction `vst1.64 {d16, d17}, [r0:128]` is generated which crashes if
the pointer value is not aligned properly.
I created a corresponding ticket with Eigen [2] which points to this issue and
has extra info.
Looking at the stdlib implementation of libc++ [3] and MSVC [4] I see a similar
approach as proposed in the attached patch.
[1] https://godbolt.org/z/1TxcTzz53
[2] https://gitlab.com/libeigen/eigen/-/issues/2826
[3]
https://github.com/llvm/llvm-project/blob/main/libcxx/include/__memory/temporary_buffer.h#L26
[4] https://github.com/microsoft/STL/blob/main/stl/inc/xmemory#L1541
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (7 preceding siblings ...)
2024-05-31 7:39 ` Marco.Porsch at intenta dot de
@ 2024-05-31 9:58 ` redi at gcc dot gnu.org
2024-06-01 10:32 ` redi at gcc dot gnu.org
2024-06-03 20:18 ` cvs-commit at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-31 9:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The patch needs a little refactoring to share code with std::stacktrace, but it
will be fixed soon.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (8 preceding siblings ...)
2024-05-31 9:58 ` redi at gcc dot gnu.org
@ 2024-06-01 10:32 ` redi at gcc dot gnu.org
2024-06-03 20:18 ` cvs-commit at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-01 10:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2024-June/65
| |3296.html
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Patch posted: https://gcc.gnu.org/pipermail/gcc-patches/2024-June/653296.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/105258] std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
2022-04-13 8:37 [Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort()) wielkiegie at gmail dot com
` (9 preceding siblings ...)
2024-06-01 10:32 ` redi at gcc dot gnu.org
@ 2024-06-03 20:18 ` cvs-commit at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-03 20:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:b0efdcbf58a76af3b8fff75f1d53d334fb5b46ee
commit r15-997-gb0efdcbf58a76af3b8fff75f1d53d334fb5b46ee
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Apr 13 13:03:44 2022 +0100
libstdc++: Handle extended alignment in std::get_temporary_buffer
[PR105258]
This adds extended alignment support to std::get_temporary_buffer etc.
so that when std::stable_sort uses a temporary buffer it works for
overaligned types.
Also simplify the _Temporary_buffer type by using RAII for the
allocation, via a new data member. This simplifies the _Temporary_buffer
constructor and destructor by makingthem only responsible for
constructing and destroying the elements, not managing the memory.
libstdc++-v3/ChangeLog:
PR libstdc++/105258
* include/bits/stl_tempbuf.h (__detail::__get_temporary_buffer):
New function to do allocation for get_temporary_buffer, with
extended alignment support.
(__detail::__return_temporary_buffer): Support extended
alignment.
(get_temporary_buffer): Use __get_temporary_buffer.
(return_temporary_buffer): Support extended alignment. Add
deprecated attribute.
(_Temporary_buffer): Move allocation and deallocation into a
subobject and remove try-catch block in constructor.
(__uninitialized_construct_buf): Use argument deduction for
value type.
* testsuite/20_util/temporary_buffer.cc: Add dg-warning for new
deprecated warning.
* testsuite/25_algorithms/stable_sort/overaligned.cc: New test.
^ permalink raw reply [flat|nested] 12+ messages in thread