LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>,
David Miller <davem@davemloft.net>,
linux-next@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Travis <travis@sgi.com>
Subject: Re: linux-next: build failure
Date: Tue, 29 Jul 2008 09:26:03 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.1.10.0807290918460.3334@nehalem.linux-foundation.org> (raw)
In-Reply-To: <20080729080055.GA28916@elte.hu>
On Tue, 29 Jul 2008, Ingo Molnar wrote:
>
> > @@ -287,7 +287,7 @@ static inline const cpumask_t *get_cpu_mask(unsigned int cpu)
> > * gcc optimizes it out (it's a constant) and there's no huge stack
> > * variable created:
> > */
> > -#define cpumask_of_cpu(cpu) ({ *get_cpu_mask(cpu); })
> > +#define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
>
> hm, i'm wondering - is this a compiler bug?
Not necessarily. The code is fragile.
Doing a statement expression basically creates a new temporary variable
with pretty much undefined scope. Taking the address of it *may* be
optimized away to the original cpu_mask pointer, but it's not really a
well-defined operation: there really _is_ a local temporary variable, and
if you were to change things through the address-of thing, gcc would be
buggy if it had done the optimization.
So the "address-of statement expression" really is a dubious construct.
That said, the change that Stephen introduces is _not_ a no-op. It very
fundamentally changes the code - exactly because now there is no temporary
value created any more: it's a real lvalue, and now anybody who does
&cpumask_of_cpu(cpu) will fundamentally get the original pointer back,
except it has lost the "const".
And that's actually dangerous - exactly because it now loses the "const"
thing, there may be people who end up modifying the result without
getting any compile-time warnings.
I would _seriously_ suggest that both the original code and Stephen's
modified version is really bad. And you should have taken my interface
as-is - one that returns a "const cpumask_t *", and nothing else.
Anything else is simply fundamentally broken.
Linus
next prev parent reply other threads:[~2008-07-29 16:29 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-29 6:23 Stephen Rothwell
2008-07-29 8:00 ` Ingo Molnar
2008-07-29 8:03 ` Stephen Rothwell
2008-07-29 8:58 ` Ingo Molnar
2008-07-29 11:28 ` KOSAKI Motohiro
2008-07-29 11:40 ` Ingo Molnar
2008-07-29 14:31 ` Mike Travis
2008-07-29 14:33 ` Mike Travis
2008-07-29 16:33 ` Linus Torvalds
2008-07-29 16:42 ` Ingo Molnar
2008-07-29 16:44 ` Linus Torvalds
2008-07-29 8:14 ` Wenji Huang
2008-07-29 16:26 ` Linus Torvalds [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-11-08 16:51 linux-next " Mark Salter
2013-10-30 15:27 Mark Salter
2013-10-30 20:37 ` Stephen Rothwell
2013-10-30 20:50 ` Andrew Morton
2013-10-30 23:17 ` Stephen Rothwell
2008-10-20 12:04 linux-next: " Stephen Rothwell
2008-10-20 15:48 ` Greg KH
2008-10-20 16:33 ` J.R. Mauro
2008-10-20 16:51 ` Greg KH
2008-10-20 20:47 ` Greg KH
2008-10-20 22:34 ` J.R. Mauro
2008-10-20 22:31 ` Stephen Rothwell
2008-08-25 11:28 Stephen Rothwell
2008-08-25 12:40 ` Ingo Molnar
2008-08-28 7:40 ` David Miller
2008-07-28 5:07 Stephen Rothwell
2008-07-28 4:44 Stephen Rothwell
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=alpine.LFD.1.10.0807290918460.3334@nehalem.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=sfr@canb.auug.org.au \
--cc=travis@sgi.com \
--subject='Re: linux-next: build failure' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).