This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix -Wshadow=local warnings in passes.c


Hi,

this fixes -Wshadow=local warnings in passes.c.
The non-trivial part is due to the PUSH_INSERT_PASSES_WITHIN
is used recursively, and shadows the local value p
in each invocation.

Fixed by using a helper class that restores the saved content
of p at the end of the block.

The shadowing variable in ipa_write_summaries can simply be
removed sine the outer variable of the same name has the
same type and is not live here, this is a trivial change.


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.

2019-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* passes.c (push_pass_state): New helper class.
	(PUSH_INSERT_PASSES_WITHIN): Use push_pass_state.
	(ipa_write_summaries): Remove shadowing local var.

Index: gcc/passes.c
===================================================================
--- gcc/passes.c	(revision 276484)
+++ gcc/passes.c	(working copy)
@@ -1491,6 +1491,30 @@ pass_manager::register_pass (struct register_pass_
     }
 }
 
+/* Helper class that is used in PUSH_INSERT_PASSES_WITHIN
+   to push the current state of the local variable "p",
+   and restore it again to the previous state after the
+   current block is closed.  */
+
+class push_pass_state
+{
+  public:
+    push_pass_state (opt_pass **&val)
+    : m_val (val)
+    { 
+      m_org = m_val;
+    }
+
+    ~push_pass_state()
+    {
+      m_val = m_org;
+    }
+
+  private:
+    opt_pass **&m_val;
+    opt_pass **m_org;
+};
+
 /* Construct the pass tree.  The sequencing of passes is driven by
    the cgraph routines:
 
@@ -1556,7 +1580,8 @@ pass_manager::pass_manager (context *ctxt)
 
 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
   { \
-    opt_pass **p = &(PASS ## _1)->sub;
+    push_pass_state scope_ ## PASS (p);		\
+    p = &(PASS ## _1)->sub;
 
 #define POP_INSERT_PASSES() \
   }
@@ -2703,7 +2728,7 @@ ipa_write_summaries (void)
 
   for (i = order_pos - 1; i >= 0; i--)
     {
-      struct cgraph_node *node = order[i];
+      node = order[i];
 
       if (gimple_has_body_p (node->decl))
 	{

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]