public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Jan Kara <jack@suse.cz>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
	Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dcache: use QSTR() instead of QSTR_INIT()
Date: Wed, 22 Apr 2026 16:41:21 +0100	[thread overview]
Message-ID: <20260422154121.GL3518998@ZenIV> (raw)
In-Reply-To: <6kjrb7mchttfnh6cx2av3aqk3y24346rrl462psfrhjwgle7n3@l77coamhara6>

On Wed, Apr 22, 2026 at 05:04:54PM +0200, Jan Kara wrote:
> On Wed 22-04-26 15:34:37, Al Viro wrote:
> > On Wed, Apr 22, 2026 at 02:33:46PM +0200, Thorsten Blum wrote:
> > > Drop the hard-coded length arguments and use the simpler QSTR().
> > 
> > ... which is not a constant expression.  NAK.
> > 
> > QSTR_INIT() is an initializer list for struct qstr; QSTR() is a
> > compound literal for the same.  IOW, its value is an anonymous
> > local variable with given contents.
> > 
> > C grammar allows both
> > 	struct foo x = {.bar = y};
> > and
> > 	struct foo x = (struct foo){.bar = y};
> > for auto variables, and compiler is able to figure out that they
> > are equivalent.  But the second form is not legal for the static-duration
> > variables.
> 
> Hum, I understand your reasoning but if it isn't legal, I'd expect the
> compiler to complain. Which it doesn't and the generated binary of a sample
> test program with both constructs is exactly the same...

gcc is treating that as an extension, without having clearly documented it.  

Again, compound literal is *not* a fancier way to spell the initializer list;
it's equivalent to having an anonymous local variable with initializer list.
It's an l-value, which quite a few uses of QSTR rely upon (and which the
same patch series misses in several places, keeping useless named locals
for no reason).

It really makes no sense for static storage-duration objects; optimization
I've mentioned above is basically a compiler seeing that
	struct foo anon = <initializer>
	struct foo x = anon;
with no uses of anon anywhere else and figuring out that anon can be eliminated.
Doing something similar for global variables is insane - would you expect

static int __x = 1;
int x = __x;
<no other uses of __x>

to be valid C?  Sure, you can prove that the value of __x will be 1 all along -
no stores to it anywhere, so the value of expression used to initialize x could
be deduced at compile time.  Currently gcc doesn't have that (that's *not*
a suggestion for another extension), but if that changed I'd still recommend
not to make use of such.

      reply	other threads:[~2026-04-22 15:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 12:33 [PATCH] dcache: use QSTR() instead of QSTR_INIT() Thorsten Blum
2026-04-22 12:51 ` Jan Kara
2026-04-22 14:34 ` Al Viro
2026-04-22 15:04   ` Jan Kara
2026-04-22 15:41     ` Al Viro [this message]

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=20260422154121.GL3518998@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thorsten.blum@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox