public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-11100] libstdc++: Fix std::deque::operator[] Xmethod [PR112491]
Date: Wed, 15 Nov 2023 11:42:31 +0000 (GMT) [thread overview]
Message-ID: <20231115114231.D02F83858D35@sourceware.org> (raw)
https://gcc.gnu.org/g:7cfe05d1ee351c2c01f75368a295afb3b712c056
commit r11-11100-g7cfe05d1ee351c2c01f75368a295afb3b712c056
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Nov 14 15:08:13 2023 +0000
libstdc++: Fix std::deque::operator[] Xmethod [PR112491]
The Xmethod for std::deque::operator[] has the same bug that I recently
fixed for the std::deque::size() Xmethod. The first node might have
unused capacity at the start, which needs to be accounted for when
indexing into the deque.
libstdc++-v3/ChangeLog:
PR libstdc++/112491
* python/libstdcxx/v6/xmethods.py (DequeWorkerBase.index):
Correctly handle unused capacity at the start of the first node.
* testsuite/libstdc++-xmethods/deque.cc: Check index operator
when elements have been removed from the front.
(cherry picked from commit 452476db0c705caeac8712d560fc16ced0ca5226)
Diff:
---
libstdc++-v3/python/libstdcxx/v6/xmethods.py | 12 ++++++++----
libstdc++-v3/testsuite/libstdc++-xmethods/deque.cc | 6 +++++-
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
index 5223cce76ca..a50ebca2287 100644
--- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py
+++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
@@ -170,7 +170,7 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker):
def size(self, obj):
start = obj['_M_impl']['_M_start']
finish = obj['_M_impl']['_M_finish']
- if not start['_M_node']:
+ if start['_M_cur'] == finish['_M_cur']:
return 0
return (self._bufsize
* (finish['_M_node'] - start['_M_node'] - 1)
@@ -178,9 +178,13 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker):
+ (start['_M_last'] - start['_M_cur']))
def index(self, obj, idx):
- first_node = obj['_M_impl']['_M_start']['_M_node']
- index_node = first_node + int(idx) // self._bufsize
- return index_node[0][idx % self._bufsize]
+ start = obj['_M_impl']['_M_start']
+ first_node_size = start['_M_last'] - start['_M_cur']
+ if idx < first_node_size:
+ return start['_M_cur'][idx]
+ idx = idx - first_node_size
+ index_node = start['_M_node'][1 + int(idx) // self._bufsize]
+ return index_node[idx % self._bufsize]
class DequeEmptyWorker(DequeWorkerBase):
def get_arg_types(self):
diff --git a/libstdc++-v3/testsuite/libstdc++-xmethods/deque.cc b/libstdc++-v3/testsuite/libstdc++-xmethods/deque.cc
index 1dd0bd8d875..f366d43e34f 100644
--- a/libstdc++-v3/testsuite/libstdc++-xmethods/deque.cc
+++ b/libstdc++-v3/testsuite/libstdc++-xmethods/deque.cc
@@ -69,20 +69,24 @@ main ()
// PR libstdc++/112491
std::deque<int> q5;
- q5.push_front(0);
+ q5.push_front(5);
// { dg-final { note-test q5.size() 1 } }
+// { dg-final { note-test q5\[0\] 5 } }
std::deque<int> q6 = q1;
q6.pop_front();
// { dg-final { note-test {q6.size() == (q1_size-1)} true } }
+// { dg-final { note-test q6\[1\] 102 } }
std::deque<int> q7 = q2;
q7.pop_front();
q7.pop_front();
// { dg-final { note-test {q7.size() == (q2_size-2)} true } }
+// { dg-final { note-test q7\[1\] 203 } }
std::deque<int> q8 = q3;
q8.pop_front();
q8.pop_front();
q8.pop_front();
// { dg-final { note-test {q8.size() == (q3_size-3)} true } }
+// { dg-final { note-test q8\[1\] 304 } }
std::deque<int> q9 = q8;
q9.clear();
// { dg-final { note-test q9.size() 0 } }
reply other threads:[~2023-11-15 11:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231115114231.D02F83858D35@sourceware.org \
--to=redi@gcc.gnu.org \
--cc=gcc-cvs@gcc.gnu.org \
--cc=libstdc++-cvs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).