Add operator* to gimple_stmt_iterator and gphi_iterator

Message ID 20230421135123.0BA1613456@imap2.suse-dmz.suse.de
State Repeat Merge
Headers
Series Add operator* to gimple_stmt_iterator and gphi_iterator |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Richard Biener April 21, 2023, 1:51 p.m. UTC
  This allows STL style iterator dereference.  It's the same
as gsi_stmt () or .phi ().

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	* gimple-iterator.h (gimple_stmt_iterator::operator*): Add.
	(gphi_iterator::operator*): Likewise.
---
 gcc/gimple-iterator.h | 4 ++++
 1 file changed, 4 insertions(+)
  

Patch

diff --git a/gcc/gimple-iterator.h b/gcc/gimple-iterator.h
index 38352aa95af..b709923f00d 100644
--- a/gcc/gimple-iterator.h
+++ b/gcc/gimple-iterator.h
@@ -24,6 +24,8 @@  along with GCC; see the file COPYING3.  If not see
 
 struct gimple_stmt_iterator
 {
+  gimple *operator * () const { return ptr; }
+
   /* Sequence node holding the current statement.  */
   gimple_seq_node ptr;
 
@@ -38,6 +40,8 @@  struct gimple_stmt_iterator
 /* Iterator over GIMPLE_PHI statements.  */
 struct gphi_iterator : public gimple_stmt_iterator
 {
+  gphi *operator * () const { return as_a <gphi *> (ptr); }
+
   gphi *phi () const
   {
     return as_a <gphi *> (ptr);