Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost::core::launder bug in BOOST_MSVC #160

Closed
alandefreitas opened this issue Jan 4, 2024 · 5 comments
Closed

boost::core::launder bug in BOOST_MSVC #160

alandefreitas opened this issue Jan 4, 2024 · 5 comments

Comments

@alandefreitas
Copy link
Member

boostorg/optional@8375df7 included a workaround for a problem related to boost::core::launder. The problem was reported at boostorg/optional#122.

The problem happens due to an MSVC bug and it would be best to bypass MSVC directly in Boost.Core than to have this logic replicated in other libraries.

@pdimov
Copy link
Member

pdimov commented Jan 4, 2024

To clarify, the problem is an internal compiler error with toolset=msvc-14.1 cxxstd=17 variant=release address-model=32, caused by the use of boost::core::launder (which calls std::launder in this case).

@Lastique
Copy link
Member

Lastique commented Jan 4, 2024

Perhaps, it could be emulated with __asm { nop ptr }; or something?

@pdimov
Copy link
Member

pdimov commented Jan 4, 2024

I don't think this is what it does.

@Lastique
Copy link
Member

Lastique commented Jan 4, 2024

I think, something like this should have the effect of std::launder:

template< typename T >
T* launder(T* ptr)
{
    T* res;
    __asm
    {
        mov eax, ptr
        mov res, eax
    };
    return res;
}

But that's two instructions. I suggested a nop because it may be enough for the compiler to stop assuming anything about ptr, and that's just one instruction. Sure, ideally, there should be zero instructions, though.

@pdimov
Copy link
Member

pdimov commented Jan 4, 2024

MSVC doesn't perform the optimizations against which std::launder guards, so the correct emulation of it today is a no-op.

If it starts doing them some day, and for some reason std::launder doesn't work on that hypothetical future version only in 32 bit mode, maybe the above will work.

@pdimov pdimov closed this as completed in e4adc76 Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants