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

Access violation when returing object with specific layout on MSVC #172

Open
Lyulf opened this issue Apr 17, 2024 · 8 comments
Open

Access violation when returing object with specific layout on MSVC #172

Lyulf opened this issue Apr 17, 2024 · 8 comments

Comments

@Lyulf
Copy link

Lyulf commented Apr 17, 2024

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.

@Pele44
Copy link

Pele44 commented Apr 18, 2024

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.

@Pele44
Copy link

Pele44 commented Apr 26, 2024

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.

@klemens-morgenstern
Copy link
Collaborator

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.

@Pele44
Copy link

Pele44 commented Apr 26, 2024

Thanks for the answer!

@fgoujeon
Copy link

It this related to this MSVC bug?

@klemens-morgenstern
Copy link
Collaborator

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.

@Lyulf
Copy link
Author

Lyulf commented Apr 30, 2024

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.

@Pele44
Copy link

Pele44 commented Jul 12, 2024

Is there a chance that the mentioned bug/workaround for the MSVC bug will be fixed in the near future?

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

4 participants