From: Julien Grall <julien.grall@citrix.com>
To: Jan Beulich <JBeulich@suse.com>,
George Dunlap <George.Dunlap@eu.citrix.com>
Cc: KeirFraser <keir@xen.org>, IanCampbell <ian.campbell@citrix.com>,
Dario Faggioli <dario.faggioli@citrix.com>,
Tim Deegan <tim@xen.org>,
Stefano Stabellini <stefano.stabellini@citrix.com>,
xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 0/6] Remove some usage of shadow variable
Date: Wed, 28 Oct 2015 09:10:07 +0000 [thread overview]
Message-ID: <563090EF.6040006@citrix.com> (raw)
In-Reply-To: <56309AFF02000078000AF718@prv-mh.provo.novell.com>
Hi Jan,
On 28/10/2015 08:53, Jan Beulich wrote:
>>>> On 27.10.15 at 18:41, <George.Dunlap@eu.citrix.com> wrote:
>> On Tue, Oct 27, 2015 at 4:03 PM, Jan Beulich <JBeulich@suse.com> wrote:
>>>>>> On 27.10.15 at 16:39, <julien.grall@citrix.com> wrote:
>>>> I'd like to have some input to know whether turning on -Wshadow would be
>>>> sensible in the future.
>>>
>>> I think there are cases where using a shadowed variable might make
>>> sense, and hence I wouldn't want to see the warning turned on by
>>> default.
>>
>> Hmm, I'm having trouble coming up with good uses off the top of my
>> head. And are there any uses for which the value outweighs the value
>> of having the warning?
>
> First of all - macros using the ({}) gcc extension. And second variables
> whose name is kind of natural (e.g. "d" for struct domain * instances)
> but which are intentionally shadowing a larger scope one in order to
> not clobber that one's value.
IHMO using variable is a very bad practice. It make patch review more
difficult as you need to check that you effectively modify the correct
version of the variable. I've got in mind patch #3 where we have
something like that:
int frame;
[...]
if ( foo )
{
int frame;
frame = smth;
}
frame = smth;
While I agree that shadow variable could make sense in macros using
({}), all the variables in it are prefixed with _ and we can ensure that
the variable name is never re-used in other variables.
For instance min_t and max_t are using _x/_y. We could rename
_min1/_min2 for min_t and then _max1/_max2 for max_t.
>> And in line with my response to Andrew -- could we enable -Wshadow
>> until we find a use for shadowing whose value outweighs the risks of
>> building without it?
>
> Risking - along the lines of what Andrew said - build breakage for
> random people, just due to the gcc version they happen to use?
> I'm usually getting pretty upset when running into problems specific
> to certain gcc versions, where people fairly clearly didn't think about
> making their code sufficiently general. I don't know how people will
> feel if we intentionally break their build (well, not really intentionally,
> but we'd intentionally take the risk of doing so).
>
> And then, simply based on the patches that Julien sent so far: Are
> we suspecting any bugs because of shadowing variables? None of
> his patches fixed anything; they were just cleanup for cases where
> the shadowing was pointless (and perhaps not even intended).
FWIW, I haven't yet removed all the shadow variables because the other
are more complex to understand.
My main concern with shadow variables is we may introduce at some point
a bug because the patch doesn't show which version of the variable you
are modifying. Worth, you may not spot there is a shadow version even if
you apply the patch to the tree and look at the code.
--
Julien Grall
next prev parent reply other threads:[~2015-10-28 9:11 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 15:39 [PATCH 0/6] Remove some usage of shadow variable Julien Grall
2015-10-27 15:39 ` [PATCH 1/6] xen/arm: domain_build: Avoid to shadow the variable "mod" in write_properties Julien Grall
2015-11-03 17:01 ` Ian Campbell
2015-10-27 15:39 ` [PATCH 2/6] xen/common: domain: Avoid to shadow the variable "d" in do_vcpu_op Julien Grall
2015-10-27 15:39 ` [PATCH 3/6] xen/common: grant_table: Avoid to shadow "frame" in __gnttab_map_grant_ref Julien Grall
2015-10-27 16:22 ` Jan Beulich
2015-10-27 15:39 ` [PATCH 4/6] xen/common: memory: Avoid to shadow the variable "d" in do_memory_op Julien Grall
2015-10-27 16:25 ` Jan Beulich
2015-10-27 16:51 ` Julien Grall
2015-10-27 15:39 ` [PATCH 5/6] xen/common: sched: Avoid to shadow the variable "cur" in runq_tickle Julien Grall
2015-10-27 15:59 ` Dario Faggioli
2015-10-27 16:27 ` Jan Beulich
2015-10-27 17:00 ` Julien Grall
2015-10-27 15:39 ` [PATCH 6/6] xen/common: sched-rt: Avoid to shadow the variable "svc" in rt_dom_cntl Julien Grall
2015-10-27 16:17 ` Dario Faggioli
2015-10-27 16:03 ` [PATCH 0/6] Remove some usage of shadow variable Jan Beulich
2015-10-27 17:41 ` George Dunlap
2015-10-28 8:53 ` Jan Beulich
2015-10-28 9:10 ` Julien Grall [this message]
2015-10-28 9:27 ` Jan Beulich
2015-10-28 9:12 ` Juergen Gross
2015-10-28 9:31 ` Jan Beulich
2015-10-28 9:44 ` Juergen Gross
2015-10-28 10:50 ` George Dunlap
2015-10-28 11:50 ` Jan Beulich
2015-10-27 16:12 ` Andrew Cooper
2015-10-27 17:39 ` George Dunlap
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=563090EF.6040006@citrix.com \
--to=julien.grall@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=dario.faggioli@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=keir@xen.org \
--cc=stefano.stabellini@citrix.com \
--cc=tim@xen.org \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.