public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32911]  New: Function __attribute__ ((idempotent))
@ 2007-07-27  6:33 gnu at behdad dot org
  2007-07-27  9:35 ` [Bug middle-end/32911] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 8+ messages in thread
From: gnu at behdad dot org @ 2007-07-27  6:33 UTC (permalink / raw)
  To: gcc-bugs

In GNOME's gobject object-oriented code, each type has a "get_type" function. 
Something like, eg:

GType
pango_layout_line_get_type(void)
{
  static GType our_type = 0;

  if (our_type == 0)
    our_type = g_boxed_type_register_static (I_("PangoLayoutLine"),
                           (GBoxedCopyFunc) pango_layout_line_ref,
                           (GBoxedFreeFunc) pango_layout_line_unref);
  return our_type;
}

Since these functions are called quite frequently (as part of casts among other
things), people have started marking them with __attribute__((const)) so the
compiler can optimize away multiple calls to them.  However, there is a down
side to it.  Sometimes one needs to make sure the type is registered, so they
call the _get_type() function to ensure that, but the compiler, seeing the
((const)) attribute, optimizes away the call.

This is of course a bug to mark functions with side-effects as ((const)). 
That's why a new function attribute like "idempotent" is useful.  What it means
is that subsequent calls to this function return the same value as the first
call, have no side-effect, and can be optimized away, but not the first call...

Thanks,


-- 
           Summary: Function __attribute__ ((idempotent))
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gnu at behdad dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32911


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

end of thread, other threads:[~2024-06-01  4:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-32911-4@http.gcc.gnu.org/bugzilla/>
2012-05-15 15:57 ` [Bug middle-end/32911] Function __attribute__ ((idempotent)) walters at verbum dot org
2012-05-15 15:57   ` Jan Hubicka
2012-05-15 16:00 ` hubicka at ucw dot cz
2012-05-15 16:18 ` hubicka at gcc dot gnu.org
2020-08-06 13:05 ` matthew at wil dot cx
2021-09-04 10:27 ` trass3r at gmail dot com
2024-06-01  4:09 ` egallager at gcc dot gnu.org
2007-07-27  6:33 [Bug c/32911] New: " gnu at behdad dot org
2007-07-27  9:35 ` [Bug middle-end/32911] " pinskia at gcc dot gnu dot org

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