This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix -Wshadow=local warnings in passes.c
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 3 Oct 2019 15:18:16 +0000
- Subject: [PATCH] Fix -Wshadow=local warnings in passes.c
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KytUndJJBDebWcWPqwAIih0CDrMgDf9R6qg6ylX1iTE=; b=Not/caHDWgXAkpzdv1uiO80Zf3BsrCyX0ldowwzZAIE/l2Gh50oI6XzUP0LFmp8s2ome1K3QSHMU57XmuxsNDBOn0Kr9giUvi6QI6+zAJ6D6c9YfGRinNKIT6IpLJmJ5hE+xt+RdAa5q8s11dG4Tyu47pa5X/zV4DHmr54PIknSR2bb+rJ1AGRElfjczKgrlgoIfPdjsxXGcgBrRYOikivakPc1fszYaSLp361rZdOAhc+obGeybKsytzHeOHXRlTcXnVh98MTLuhSSKy6Lbl0BZpAxvqhx2CYULc6beKtOMCnx9aXOByu07gczvg7FrtBmp8+MLc17JBj1CUEwZ9A==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ikCWRtW+3nQTZx3GJpk1taUgPRYOpDTZCwPuXlvgBJx47eY7xE4cN2Lqf9kJuHxcPKGsb6ELh/vpffaLS4cQHqt6ykYiJ4/TvQpTmZWiTOWIiZsPXx6MXHH+rKU+T/1D/CEaAKTIsJvWsS1sTzHPCbwCUhiUst3XHhLHypOovvAUThaMTbkzEW4o/SRSUNQtWLMGODE81tjxDgrgKh9ihBzP0jQArnZB4klLwxG9pO4vLgJnp5F1L0T8iMbapDfhSARqp6eHN5TDYArvUoTj604XxnEi/cyr5AtJgksgg60/Bm/od1WKRNveKVNoqLMPT5ARJ9fSjqs3COJlyj8i+g==
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))
{