From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24148 invoked by alias); 27 Jul 2007 06:33:57 -0000 Received: (qmail 24122 invoked by uid 48); 27 Jul 2007 06:33:47 -0000 Date: Fri, 27 Jul 2007 06:33:00 -0000 Subject: [Bug c/32911] New: Function __attribute__ ((idempotent)) X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "gnu at behdad dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-07/txt/msg02733.txt.bz2 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