public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Peter Zijlstra <peterz@infradead.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Richard Biener <richard.guenther@gmail.com>,
	 "Uecker, Martin" <Martin.Uecker@med.uni-goettingen.de>,
	"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>,
	 "amonakov@ispras.ru" <amonakov@ispras.ru>,
	"ubizjak@gmail.com" <ubizjak@gmail.com>,
	 "luto@kernel.org" <luto@kernel.org>,
	linux-toolchains@vger.kernel.org,  Will Deacon <will@kernel.org>,
	Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: Re: typeof and operands in named address spaces
Date: Tue, 17 Nov 2020 11:47:04 -0800	[thread overview]
Message-ID: <CAHk-=wivBmCoux_bVz_tZ12byZS=oZ7+F2Og8OjJGM5aiM-KQQ@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wh_kn11vXfi2Ns8E4F0GgmUprQtD-=RnU6Eg+N7coY5gw@mail.gmail.com>

On Tue, Nov 17, 2020 at 11:13 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> > +#define __unqual_typeof(type)  typeof( (typeof(type))type )
>
> that's certainly a much nicer version than the existing pre-processor
> expansion from hell.

Oh, and sparse doesn't handle this, and doesn't remove any qualifiers
for the above. And so this horror-test-case fails:

    #define __unqual_typeof(type)  typeof( (typeof(type))(type) )

    int *function(volatile int x)
    {
        extern __unqual_typeof(x) y;
        return &y;
    }

with

  t.c:6:17: warning: incorrect type in return expression (different modifiers)
  t.c:6:17:    expected int *
  t.c:6:17:    got int volatile *
  t.c:3:5: warning: symbol 'function' was not declared. Should it be static?

adding Luc and the sparse mailing list to the participants list.

But it does work with both gcc and clang for me.

For Luc, quoting some earlier emails:

> > lvalue conversion drops qualifers in C.  In GCC, this is not
> > implemented correctly as it is unobservable 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) )

on another thing that fails with sparse. But since gcc gets that wrong
too and it only works with clang, that's not so relevant for the
kernel.

Luc - same test-case as above, just

    #define __unqual_typeof(x) typeof( ((void)0, (x)) )

instead.

           Linus

      parent reply	other threads:[~2020-11-17 19:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-15 10:51 Uecker, Martin
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 [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='CAHk-=wivBmCoux_bVz_tZ12byZS=oZ7+F2Og8OjJGM5aiM-KQQ@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=Martin.Uecker@med.uni-goettingen.de \
    --cc=amonakov@ispras.ru \
    --cc=gcc@gcc.gnu.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=richard.guenther@gmail.com \
    --cc=ubizjak@gmail.com \
    --cc=will@kernel.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 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).