This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++17 std::launder and aliasing


On 21/10/16 20:07 +0200, Jakub Jelinek wrote:
On Fri, Oct 21, 2016 at 08:54:42PM +0300, Ville Voutilainen wrote:
>> Or we could add a typegeneric __builtin_launder builtin that would
>> immediately fold to its argument.  Then we can change it any time we
>> figure
>> out we need to do something there.
>
>
> That would work too. I shoulda left this thread on gcc@ :-)
>
> As an aside, __has_builtin is pretty useful (like __has_include and
> __has_attribute).
>
>

Richard Smith is suggesting that gcc needs a real launder:
https://godbolt.org/g/Ymdm0Y

Seems that testcase is devirtualization related.
With -O3 -fno-devirtualize we return 3 (but still no calls).
With asm ("" : "+g" (p)); before return p; in launder we don't devirtualize
it any more and return 3 in the end.  Is the testcase only valid
with std::launder and not valid otherwise (I hope so, otherwise we are in
big trouble with devirtualization)?

It's definitely not valid if the call to launder is not there.

Without the launder, the compiler is correct to assume that 'a' still
refers to the same object. But it must not assume that
*std::launder(&a) refers to that object, so it should not devirtualize
through that expression.

i.e. std::launder(&a) is not equivalent to &a, so a no-op isn't good
enough.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]