From ec3e3110dea7ec8fcfc97b971fdd5382891296ee Mon Sep 17 00:00:00 2001 From: redi Date: Thu, 15 Dec 2016 14:13:36 +0000 Subject: [PATCH] PR59170 make pretty printers check for singular iterators PR libstdc++/59170 * python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string) (StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string) (StdRbtreeIteratorPrinter.to_string) (StdDequeIteratorPrinter.to_string): Add check for value-initialized iterators. * testsuite/libstdc++-prettyprinters/simple.cc: Test them. * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@243692 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 9 ++++++++ libstdc++-v3/python/libstdcxx/v6/printers.py | 10 ++++++++ .../testsuite/libstdc++-prettyprinters/simple.cc | 27 ++++++++++++++++++++++ .../testsuite/libstdc++-prettyprinters/simple11.cc | 27 ++++++++++++++++++++++ 4 files changed, 73 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7b5bd259173..cbed9d881c7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2016-12-15 Jonathan Wakely + PR libstdc++/59170 + * python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string) + (StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string) + (StdRbtreeIteratorPrinter.to_string) + (StdDequeIteratorPrinter.to_string): Add check for value-initialized + iterators. + * testsuite/libstdc++-prettyprinters/simple.cc: Test them. + * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. + PR libstdc++/59161 * python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string) (StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index ab3592a7e67..86de1ca5263 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -200,6 +200,8 @@ class StdListIteratorPrinter: self.typename = typename def to_string(self): + if not self.val['_M_node']: + return 'non-dereferenceable iterator for std::list' nodetype = find_type(self.val.type, '_Node') nodetype = nodetype.strip_typedefs().pointer() node = self.val['_M_node'].cast(nodetype).dereference() @@ -246,6 +248,8 @@ class StdSlistIteratorPrinter: self.val = val def to_string(self): + if not self.val['_M_node']: + return 'non-dereferenceable iterator for __gnu_cxx::slist' nodetype = find_type(self.val.type, '_Node') nodetype = nodetype.strip_typedefs().pointer() return str(self.val['_M_node'].cast(nodetype).dereference()['_M_data']) @@ -333,6 +337,8 @@ class StdVectorIteratorPrinter: self.val = val def to_string(self): + if not self.val['_M_current']: + return 'non-dereferenceable iterator for std::vector' return str(self.val['_M_current'].dereference()) class StdTuplePrinter: @@ -494,6 +500,8 @@ class StdRbtreeIteratorPrinter: self.link_type = nodetype.strip_typedefs().pointer() def to_string (self): + if not self.val['_M_node']: + return 'non-dereferenceable iterator for associative container' node = self.val['_M_node'].cast(self.link_type).dereference() return str(get_value_from_Rb_tree_node(node)) @@ -708,6 +716,8 @@ class StdDequeIteratorPrinter: self.val = val def to_string(self): + if not self.val['_M_cur']: + return 'non-dereferenceable iterator for std::deque' return str(self.val['_M_cur'].dereference()) class StdStringPrinter: diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc index fb8e0d754e6..35fbb90816b 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include int @@ -50,6 +51,9 @@ main() deq.push_back("two"); // { dg-final { note-test deq {std::deque with 2 elements = {"one", "two"}} } } + std::deque::iterator deqiter0; +// { dg-final { note-test deqiter0 {non-dereferenceable iterator for std::deque} } } + std::deque::iterator deqiter = deq.begin(); // { dg-final { note-test deqiter {"one"} } } @@ -58,6 +62,9 @@ main() lst.push_back("two"); // { dg-final { note-test lst {std::list = {[0] = "one", [1] = "two"}} } } + std::list::iterator lstiter0; +// { dg-final { note-test lstiter0 {non-dereferenceable iterator for std::list} } } + std::list::iterator lstiter = lst.begin(); tem = *lstiter; // { dg-final { note-test lstiter {"one"}} } @@ -73,6 +80,9 @@ main() std::map::iterator mpiter = mp.begin(); // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } } + std::map::iterator mpiter0; +// { dg-final { note-test mpiter0 {non-dereferenceable iterator for associative container} } } + // PR 67440 std::set intset; intset.insert(2); @@ -88,6 +98,20 @@ main() std::set::const_iterator spciter = sp.begin(); // { dg-final { note-test spciter {"barrel"} } } + std::set::iterator spiter0; +// { dg-final { note-test spiter0 {non-dereferenceable iterator for associative container} } } + + std::vector v; + v.push_back(1); + v.push_back(2); + v.erase(v.begin()); +// { dg-final { note-test v {std::vector of length 1, capacity 2 = {2}} } } + std::vector::iterator viter3 = v.begin(); +// { dg-final { note-test viter3 {2} } } + + std::vector::iterator viter0; +// { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } } + __gnu_cxx::slist sll; sll.push_front(23); sll.push_front(47); @@ -96,6 +120,9 @@ main() __gnu_cxx::slist::iterator slliter = sll.begin(); // { dg-final { note-test slliter {47} } } + __gnu_cxx::slist::iterator slliter0; +// { dg-final { note-test slliter0 {non-dereferenceable iterator for __gnu_cxx::slist} } } + std::cout << "\n"; return 0; // Mark SPOT } diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc index 9e230e3d4d9..8efe00e8134 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include int @@ -53,6 +54,9 @@ main() std::deque::iterator deqiter = deq.begin(); // { dg-final { note-test deqiter {"one"} } } + std::deque::iterator deqiter0; +// { dg-final { note-test deqiter0 {non-dereferenceable iterator for std::deque} } } + std::list lst; lst.push_back("one"); lst.push_back("two"); @@ -66,6 +70,9 @@ main() tem = *lstciter; // { dg-final { note-test lstciter {"one"}} } + std::list::iterator lstiter0; +// { dg-final { note-test lstiter0 {non-dereferenceable iterator for std::list} } } + std::map mp; mp["zardoz"] = 23; // { dg-final { note-test mp {std::map with 1 element = {["zardoz"] = 23}} } } @@ -73,6 +80,9 @@ main() std::map::iterator mpiter = mp.begin(); // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } } + std::map::iterator mpiter0; +// { dg-final { note-test mpiter0 {non-dereferenceable iterator for associative container} } } + // PR 67440 const std::set const_intset = {2, 3}; // { dg-final { note-test const_intset {std::set with 2 elements = {[0] = 2, [1] = 3}} } } @@ -85,6 +95,20 @@ main() std::set::const_iterator spciter = sp.begin(); // { dg-final { note-test spciter {"barrel"} } } + std::set::iterator spiter0; +// { dg-final { note-test spiter0 {non-dereferenceable iterator for associative container} } } + + std::vector v; + v.push_back(1); + v.push_back(2); + v.erase(v.begin()); +// { dg-final { note-test v {std::vector of length 1, capacity 2 = {2}} } } + std::vector::iterator viter3 = v.begin(); +// { dg-final { note-test viter3 {2} } } + + std::vector::iterator viter0; +// { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } } + __gnu_cxx::slist sll; sll.push_front(23); sll.push_front(47); @@ -93,6 +117,9 @@ main() __gnu_cxx::slist::iterator slliter = sll.begin(); // { dg-final { note-test slliter {47} } } + __gnu_cxx::slist::iterator slliter0; +// { dg-final { note-test slliter0 {non-dereferenceable iterator for __gnu_cxx::slist} } } + std::cout << "\n"; return 0; // Mark SPOT } -- 2.11.4.GIT