public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset
@ 2024-06-08 21:21 adamant.pwn at gmail dot com
2024-06-08 22:17 ` [Bug libstdc++/115399] " adamant.pwn at gmail dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: adamant.pwn at gmail dot com @ 2024-06-08 21:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115399
Bug ID: 115399
Summary: std::tr2::dynamic_bitset shift behaves differently
from std::bitset
Product: gcc
Version: 14.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: adamant.pwn at gmail dot com
Target Milestone: ---
Target: x86-64 Linux
Build: 20240522
Posting a bug on behalf of someone who didn't manage to create an account at
GCC bugzilla due to automatic registration being disabled...
The bug is due to the line
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/tr2/dynamic_bitset.tcc#L63
being commented out in dynamic_bitset implementation (unlike std::bitset, where
it is present). Uncommenting it should fix the problem.
A simple example program to highlight the discrepancy:
#include <iostream>
#include <bitset>
#include <tr2/dynamic_bitset>
int main() {
std::tr2::dynamic_bitset<> test(91);
test[50] = true;
std::cout << test << "\n";
std::cout << (test << 78) << "\n";
std::cout << "\n";
std::bitset<91> test2;
test2[50] = true;
std::cout << test2 << "\n";
std::cout << (test2 << 78) << "\n";
}
Output:
0000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/115399] std::tr2::dynamic_bitset shift behaves differently from std::bitset
2024-06-08 21:21 [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset adamant.pwn at gmail dot com
@ 2024-06-08 22:17 ` adamant.pwn at gmail dot com
2024-06-08 22:50 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: adamant.pwn at gmail dot com @ 2024-06-08 22:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115399
--- Comment #1 from Oleksandr Kulkov <adamant.pwn at gmail dot com> ---
The bug also affects right shift for a similar reason
(https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/tr2/dynamic_bitset.tcc#L91):
#include <iostream>
#include <bitset>
#include <tr2/dynamic_bitset>
#include <boost/dynamic_bitset.hpp>
int main() {
std::tr2::dynamic_bitset<> test(128);
for (int i = 64; i < 128; i++) test[i] = 1;
std::cout << test << "\n";
std::cout << (test >> 65) << "\n\n";
boost::dynamic_bitset<> test2(128);
for (int i = 64; i < 128; i++) test2[i] = 1;
std::cout << test2 << "\n";
std::cout << (test2 >> 65) << "\n\n";
std::bitset<128> test3;
for (int i = 64; i < 128; i++) test3[i] = 1;
std::cout << test3 << "\n";
std::cout << (test3 >> 65) << "\n\n";
}
Output:
11111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000
11111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111
See also https://github.com/emsr/tr2/issues/1.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/115399] std::tr2::dynamic_bitset shift behaves differently from std::bitset
2024-06-08 21:21 [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset adamant.pwn at gmail dot com
2024-06-08 22:17 ` [Bug libstdc++/115399] " adamant.pwn at gmail dot com
@ 2024-06-08 22:50 ` pinskia at gcc dot gnu.org
2024-06-10 8:46 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-08 22:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115399
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=114498
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I think std::tr2 should be deprecated in a similar way as std::tr1 is
being considered.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/115399] std::tr2::dynamic_bitset shift behaves differently from std::bitset
2024-06-08 21:21 [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset adamant.pwn at gmail dot com
2024-06-08 22:17 ` [Bug libstdc++/115399] " adamant.pwn at gmail dot com
2024-06-08 22:50 ` pinskia at gcc dot gnu.org
@ 2024-06-10 8:46 ` redi at gcc dot gnu.org
2024-06-10 11:38 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-10 8:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115399
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-06-10
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The tr2 extensions never even got proposed for standardization and are not in
any ISO document at all. They're not well tested and nobody uses them.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/115399] std::tr2::dynamic_bitset shift behaves differently from std::bitset
2024-06-08 21:21 [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset adamant.pwn at gmail dot com
` (2 preceding siblings ...)
2024-06-10 8:46 ` redi at gcc dot gnu.org
@ 2024-06-10 11:38 ` redi at gcc dot gnu.org
2024-06-12 14:07 ` cvs-commit at gcc dot gnu.org
2024-06-12 15:57 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-10 11:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115399
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/115399] std::tr2::dynamic_bitset shift behaves differently from std::bitset
2024-06-08 21:21 [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset adamant.pwn at gmail dot com
` (3 preceding siblings ...)
2024-06-10 11:38 ` redi at gcc dot gnu.org
@ 2024-06-12 14:07 ` cvs-commit at gcc dot gnu.org
2024-06-12 15:57 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-12 14:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115399
--- Comment #4 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:bd3a312728fbf8c35a09239b9180269f938f872e
commit r15-1213-gbd3a312728fbf8c35a09239b9180269f938f872e
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Jun 10 14:08:16 2024 +0100
libstdc++: Fix std::tr2::dynamic_bitset shift operations [PR115399]
The shift operations for dynamic_bitset fail to zero out words where the
non-zero bits were shifted to a completely different word.
For a right shift we don't need to sanitize the unused bits in the high
word, because we know they were already clear and a right shift doesn't
change that.
libstdc++-v3/ChangeLog:
PR libstdc++/115399
* include/tr2/dynamic_bitset (operator>>=): Remove redundant
call to _M_do_sanitize.
* include/tr2/dynamic_bitset.tcc (_M_do_left_shift): Zero out
low bits in words that should no longer be populated.
(_M_do_right_shift): Likewise for high bits.
* testsuite/tr2/dynamic_bitset/pr115399.cc: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/115399] std::tr2::dynamic_bitset shift behaves differently from std::bitset
2024-06-08 21:21 [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset adamant.pwn at gmail dot com
` (4 preceding siblings ...)
2024-06-12 14:07 ` cvs-commit at gcc dot gnu.org
@ 2024-06-12 15:57 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-12 15:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115399
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Target Milestone|--- |15.0
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk. I'll probably backport it to the release branches at some
point.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-06-12 15:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-08 21:21 [Bug c++/115399] New: std::tr2::dynamic_bitset shift behaves differently from std::bitset adamant.pwn at gmail dot com
2024-06-08 22:17 ` [Bug libstdc++/115399] " adamant.pwn at gmail dot com
2024-06-08 22:50 ` pinskia at gcc dot gnu.org
2024-06-10 8:46 ` redi at gcc dot gnu.org
2024-06-10 11:38 ` redi at gcc dot gnu.org
2024-06-12 14:07 ` cvs-commit at gcc dot gnu.org
2024-06-12 15:57 ` redi 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).