public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <burnus@net-b.de>
To: Ian Lance Taylor <iant@google.com>
Cc: Tobias Burnus <tobias.burnus@physik.fu-berlin.de>,
	 "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: (gcc/)g++ and __restrict
Date: Sun, 22 Sep 2013 22:42:00 -0000	[thread overview]
Message-ID: <523F724E.5020808@net-b.de> (raw)
In-Reply-To: <CAKOQZ8weOhLi6QYpWrcaxWnHckgWBto4QTxCmHdiYdi_rj=NDg@mail.gmail.com>

Am 20.09.2013 16:59, schrieb Ian Lance Taylor:
> On Fri, Sep 20, 2013 at 3:07 AM, Tobias Burnus
> <tobias.burnus@physik.fu-berlin.de> wrote:
>> I was wondering how to convey to GCC that two pointers do not alias.
>> That works nicely in the argument list,
>>    void foo(mytype *__restrict__ arg)
>>
>> However, it does not seem to work for C++'s member variables. Even
>> if one has on the class the declaration with __restrict. Neither does
>> casting to a restrict pointer work.
> I'm not sure how that could work.  By definition the restrict
> qualifier is only meaningful in a specific context, with respect to
> other pointers with the restrict qualifier.  It would not make sense
> to declare that every restrict qualified pointer in the entire program
> may not conflict with every other restrict qualified pointer in the
> entire program.  That would be too limiting.

I admit that placing it on a C++ member variable is not the best place. 
However, being desperate, I thought I'd try it - and GCC accepted it. 
(As did Intel's icpc.)

> Another possibly more profitable approach would be to define a new
> function attribute.  In functions with that attribute we would declare
> that none of the pointers that were not based on each other could
> alias.  This would be difficult to use correctly but it would be
> fairly precise and might be sufficient for what you need.

Actually, I would find some casting approach best, namely:
   ptr = (__typeof(ptr) *__restrict) ptr;
or something like that. That would allow to put the restrict qualifier 
exactly on the pointer one wants to mark as such. I think one can 
already use such a cast for "volatile". Similarly, one can use ptr = 
__builtin_assume_aligned(ptr, size), which is also an assignment way to 
add an attribute to a pointer.

However, putting an attribute on the function itself would also work for me.

Tobias

      reply	other threads:[~2013-09-22 22:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20 10:07 Tobias Burnus
2013-09-20 14:59 ` Ian Lance Taylor
2013-09-22 22:42   ` Tobias Burnus [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=523F724E.5020808@net-b.de \
    --to=burnus@net-b.de \
    --cc=gcc-help@gcc.gnu.org \
    --cc=iant@google.com \
    --cc=tobias.burnus@physik.fu-berlin.de \
    /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).