public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Uecker, Martin" <Martin.Uecker@med.uni-goettingen.de>
To: "peterz@infradead.org" <peterz@infradead.org>
Cc: "ubizjak@gmail.com" <ubizjak@gmail.com>,
	"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>,
	"luto@kernel.org" <luto@kernel.org>,
	"amonakov@ispras.ru" <amonakov@ispras.ru>
Subject: Re: Re: typeof and operands in named address spaces
Date: Sun, 15 Nov 2020 10:51:19 +0000	[thread overview]
Message-ID: <1605437478.5370.9.camel@med.uni-goettingen.de> (raw)


> On Wed, Nov 04, 2020 at 07:31:42PM +0100, Uros Bizjak wrote:
> > Hello!
> > 
> > I was looking at the recent linux patch series [1] where segment
> > qualifiers (named address spaces) were introduced to handle percpu
> > variables. In the patch [2], the author mentions that:
> > 
> > --q--
> > Unfortunately, gcc does not provide a way to remove segment
> > qualifiers, which is needed to use typeof() to create local instances
> > of the per-cpu variable. For this reason, do not use the segment
> > qualifier for per-cpu variables, and do casting using the segment
> > qualifier instead.
> > --/q--
> 
> C in general does not provide means to strip qualifiers. We recently had
> a _lot_ of 'fun' trying to strip volatile from a type, see here:
> 
>   https://lore.kernel.org/lkml/875zimp0ay.fsf@mpe.ellerman.id.au
> 
> which resulted in the current __unqual_scalar_typeof() hack.
> 
> If we're going to do compiler extentions here, can we pretty please have
> a sane means of modifying qualifiers in general?

Another way to drop qualifiers is using a cast. So you
can use typeof twice:

typeof((typeof(_var))_var) tmp__; 

This also works for non-scalars but this is a GCC extension.


WG14 plans to standardize typeof. I would like to hear opinion
whether we should have typeof drop qualifiers or not.

Currently, it does not do this on all compilers I tested 
(except _Atomic on GCC) and there are also use cases for
keeping qualifiers. This is an argument for keeping qualifiers
should we standardize it, but then we need a way to drop
qualifiers.


lvalue conversion drops qualifers in C.  In GCC, this is not
implemented correctly as it is unobvervable in standard C
(but it using typeof).

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97702

A have a working patch in preparation to change this. Then you
could use

typeof( ((void)0, x) ) 

to drop qualifiers. But this would then
also do array-to-pointer conversion. I am not sure
whether this is a problem.


For fun, I tried to come up with a standard+typeof-compliant
macro that drops qualifiers for all types without doing
array-to-pointer conversion

https://github.com/uecker/unqual/blob/main/unqual.c

but recursing into multi-dim. array types causes
a macro-explosion.... (but maybe multi-dim arrays are
also not too important)


Of course, we could also introduce a new feature for
dropping qualifiers. Thoughts?

Best,
Martin



_



             reply	other threads:[~2020-11-15 10:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-15 10:51 Uecker, Martin [this message]
2020-11-16  9:11 ` Richard Biener
2020-11-16 11:10   ` Peter Zijlstra
2020-11-16 11:23     ` Peter Zijlstra
2020-11-16 12:23     ` Uecker, Martin
2020-11-16 13:07       ` Peter Zijlstra
2020-11-17 19:13     ` Linus Torvalds
2020-11-17 19:25       ` Jakub Jelinek
2020-11-17 19:31         ` Linus Torvalds
2020-11-17 21:10           ` Will Deacon
2020-11-17 22:15             ` Will Deacon
2020-11-17 21:23           ` Uecker, Martin
2020-11-17 19:47       ` Linus Torvalds

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=1605437478.5370.9.camel@med.uni-goettingen.de \
    --to=martin.uecker@med.uni-goettingen.de \
    --cc=amonakov@ispras.ru \
    --cc=gcc@gcc.gnu.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ubizjak@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).