public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Andrea Corallo <andrea.corallo@arm.com>
Cc: Stefan Franke <s.franke@bebbosoft.de>,
	gcc-help@gcc.gnu.org, stefan@franke.ms
Subject: Re: AW: AW: Correct way to express to the compiler "this does not get clobbered"?
Date: Mon, 7 Dec 2020 16:27:05 -0600	[thread overview]
Message-ID: <20201207222705.GV2672@gate.crashing.org> (raw)
In-Reply-To: <gkrwnxww2db.fsf@arm.com>

On Sat, Dec 05, 2020 at 07:10:08PM +0100, Andrea Corallo via Gcc-help wrote:
> "Stefan Franke" <s.franke@bebbosoft.de> writes:
> > typedef struct {
> >    void (* const fun_ptr)(void);
> >    const long x;
> >  } x_t;
> >
> > Declares that fun_ptr and x both are const and cannot change. So these const value can safely be propagated out of loops if the pointer to is also const and can't change. The current compiler simply ignores that knowledge.
> >
> > I cannot judge if this is a bug or a not implemented feature. But in the current implementation only the c/c++ parser cares about const whereas the compiler passes do not check constness.
> 
> You might be right if you change the code this way, but to begin with
> how do you set 'fun_ptr' if the only way to access it is through a
> pointer to const?  I suspect this is not very much a realistic case.

void f(void)
{
	x_t x = { .x = 42; .fun_ptr = f; };

...

etc.

The variable dies when the function returns, but other than that this
works fine.


Segher

  reply	other threads:[~2020-12-07 22:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 11:47 Andrea Corallo
2020-12-03 12:04 ` Richard Earnshaw
2020-12-03 12:28   ` Andrea Corallo
2020-12-03 13:06     ` Richard Earnshaw
2020-12-03 13:40       ` Andrea Corallo
2020-12-03 18:24 ` David Brown
2020-12-03 23:00   ` Andrea Corallo
2020-12-04  7:23     ` stefan
2020-12-04  9:52       ` Andrea Corallo
2020-12-04 17:27         ` Segher Boessenkool
2020-12-04 18:16           ` Andrea Corallo
2020-12-04 18:33             ` Segher Boessenkool
2020-12-04 18:45               ` Andrea Corallo
     [not found]               ` <017701d6ca6d$7dc8dc90$795a95b0$@bebbosoft.de>
2020-12-04 18:57                 ` AW: " Stefan Franke
2020-12-04 22:52                   ` Andrea Corallo
2020-12-05 14:01                     ` David Brown
2020-12-05 14:17                       ` AW: " Stefan Franke
2020-12-05 18:10                         ` Andrea Corallo
2020-12-07 22:27                           ` Segher Boessenkool [this message]
2020-12-05 19:03                         ` David Brown
2020-12-06 11:29                           ` AW: " Stefan Franke
2020-12-05 17:29                       ` Andrea Corallo
2020-12-05 19:07                         ` David Brown
2020-12-06  9:22                           ` Jonathan Wakely
2020-12-04  8:27     ` David Brown
2020-12-04 10:05       ` Andrea Corallo
2020-12-05  8:06 ` Liu Hao

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=20201207222705.GV2672@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=andrea.corallo@arm.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=s.franke@bebbosoft.de \
    --cc=stefan@franke.ms \
    /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).