Access violation when returing object with specific layout on MSVC
Code:
#include <cstdint>
#include <cstdio>
#include <string>
#include <boost/cobalt.hpp>
namespace cobalt = boost::cobalt;
struct ExampleStruct
{
std::string str;
std::uint8_t padding[32];
};
cobalt::task<ExampleStruct> getResult()
{
// error on this return
co_return {};
}
cobalt::main co_main(int /*argc*/, char** /*argv*/)
{
co_await getResult();
// Never displayed
std::puts("Done");
co_return 0;
}
Built on Windows 10 64-bit using MSVC 17.9.5 (cl version 19.39.33523 for x64) with following command:
cl /Femain.exe main.cpp /nologo /external:IC:\Users\chodorowskip\repo\deps\vc143\boost-1.85.0\include\boost-1_85 /std:c++20 /MD /Z7 /O2 /EHsc /D_WIN32_WINNT=0x0601 /W4 /external:W0 /link /PROFILE /LIBPATH:C:\Users\chodorowskip\repo\deps\vc143\boost-1.85.0\lib libboost_cobalt-vc143-mt-x64-1_85.lib
Error
Exception thrown at 0x00007FF728E265E1 in main.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Error doesn't seem to happen with debug configuration.
I've check this code on every combination of g++ 13.2 /clang++ 17.0.6, -O2 / -O0, no sanitizer / address sanitizer / thread sanitizer on Linux platform without any problems. In every case "Done" is printed and no sanitizer warning are reported. But on MSVC crash occurs (Windows 11), I can confirm it.
Is there a chance that the error is actually in cobalt? Or maybe it's better to report the case to Microsoft? The problem occurs in our project and unfortunately the current workaround is to stop using cobalt, which we would really like not to do, because it is supposed to be a very helpful library, making it easier to solve many of the problems we face. And the specificity of the project means that the code must run on packages generated using MSVC and gcc... We cannot give up the Microsoft compiler.
I had plenty of problems with MSVC and last time I checked they had issues with improper inlining (for which I added a workaround). I however don't like to say "it's their fault" as it might be mine. I didn't get around to checking the code yet - which is why I didn't respond, sorry.
Thanks for the answer!
It this related to this MSVC bug?
It might be. I added commit increasing the align here.
I don't know when I get my windows builds working again, so if you get around to test it let me know.
I couldn't figure out how to build cobalt without bootstrap and b2, so I just applied the changes from the most recent commit from the branch you provided and they don't seem to work. Still got access violation.
Is there a chance that the mentioned bug/workaround for the MSVC bug will be fixed in the near future?
Spent a lot of time converting a lot of our async callbacks to coroutines, only to find out this happens in release.
Any way this can be looked at?
EDIT: For anyone with this issue, the BOOST_COBALT_NO_PMR preprocessor definition saves the day.
Which boost version did you build with?
Boost is 1.87, MSVC is latest non-preview version (14.42.34433)