[llvm-bugs] [Bug 36750] Meyers' singleton does not work with [[gnu::const]] and -O1 to -O3

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Mar 18 15:27:45 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=36750

Antons Jeļkins <antons.jelkins at bmw.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |---
             Status|RESOLVED                    |REOPENED

--- Comment #4 from Antons Jeļkins <antons.jelkins at bmw.de> ---
I will reword this bug to say gnu::pure and then reopen it.

Reasoning:

Neither gnu::pure nor gnu::const are defined by the C++ standard. These are
implementation specific attributes defined here [1].

[1]
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes

It says that gnu::pure should be used if a function has no effects except the
return value and its return value depends only on the parameters and/or global
variables.

It says that a function annotated with gnu::pure can be subject to common
subexpression elimination and loop optimization just as an arithmetic operator
would be, and it is safe to call it fewer times than the program says.

I would like also to quote a GCC developer [2]:

> But if we are allowed to DCE a lazy_i call with unused result then it
> really is "pure". Basically with this property we consider the static
> variable it writes to as local, as it cannot be inspected in any other
> way than by calling the function or inspecting its return value.

[2] https://gcc.gnu.org/ml/gcc/2012-10/msg00029.html

Summarising the said above, gnu::pure does not require a function not to have
side-effects in so strict sense. Static local variables are fine. Thus the
optimisation performed by clang is invalid and the MyClass object must be
constructed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180318/9c31edf0/attachment.html>


More information about the llvm-bugs mailing list