[cfe-commits] [PATCH] Allow inline assembly to inherit readnone/readonly attributes from parent function

Jordy Rose jediknil at belkadan.com
Wed May 2 17:28:22 PDT 2012

On May 2, 2012, at 17:23, Eli Friedman wrote:

> It's not obvious to me that this is safe... __attribute((const)) means
> that a function doesn't cause expose any side-effects, not that it
> doesn't have any internal state.

I'm not a language [extension] lawyer, but as I understand it the intention of the [[const]] attribute is that such functions should /always/ be subject to CSE, even if they are /not/ truly stateless. Think about the case where you /don't/ have the implementation, just the header file. To quote the GCC manual:

> [[pure]]: Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure. For example,
> int square (int) __attribute__ ((pure));
> says that the hypothetical function square is safe to call fewer times than the program says.

> [[const]]: Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute [above], since function is not allowed to read global memory.
> Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void.

I'm not sure how this interacts with inline asm, though, or indeed inlining in general.


More information about the cfe-commits mailing list