public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Correct way to express to the compiler "this does not get clobbered"?
@ 2020-12-03 11:47 Andrea Corallo
  2020-12-03 12:04 ` Richard Earnshaw
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Andrea Corallo @ 2020-12-03 11:47 UTC (permalink / raw)
  To: gcc-help; +Cc: nd

Hi all,

I've a piece of code that reduced looks like this:

#+begin_src C
typedef struct {
  void (*fun_ptr)(void);
} x_t;

x_t *x;

void
f (void)
{
  const x_t const *y = x;
  for (int i = 0; i < 1000; ++i)
    y->fun_ptr ();
}
#+end_src

What is the correct way (if any) to express to the compiler that the
value of y->fun_ptr does not get clobbered by the function call itself
so the corresponding load to obtain its value can be moved out of the
loop?

My understanding is that the const qualifier is more for diagnostic
reasons and is not sufficient for GCC to make this assumption.  OTOH I
cannot give 'fun_ptr' the attribute pure as it's not.

Thanks

  Andrea

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-12-07 22:28 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 11:47 Correct way to express to the compiler "this does not get clobbered"? 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
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

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).