Skip to content

Bad assembly with SimpleArray caster #283

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

Closed
tigercosmos opened this issue Mar 5, 2024 · 4 comments · Fixed by #310
Closed

Bad assembly with SimpleArray caster #283

tigercosmos opened this issue Mar 5, 2024 · 4 comments · Fixed by #310
Labels
array Multi-dimensional array implementation

Comments

@tigercosmos
Copy link
Collaborator

tigercosmos commented Mar 5, 2024

In the SimpleArrayCaster.hpp file, a custom caster for SimpleArray was defined to cast from SimpleArrayPlex to SimpleArray. By default, the debug build uses the -O0 flag and the binary is incorrect. The compiler ignores the custom caster and opts for the generic caster instead. Setting the optimization level to -O1 or higher leads to a correct binary and the custom caster works correctly.

This anomaly was identified on Windows (tested with MSVC 2022) and macOS (tested with LLVM 15 and GCC 13 toolchains). Notably, Ubuntu 22.04 with GCC 11 did not exhibit this issue.

The issue was initially observed in PR#266, and a concise investigation report is available here.

As a temporary solution, a workaround involves adding a flag, DEBUG_BUILD_OPTIMIZATION_ONE, in CMake to ensure successful CI passes on Windows and macOS by applying -O1 for the debug build. By default, this flag should be set to OFF to reproduce the issue. Developers are advised to apply this CMake flag to ensure correct behavior in their local environments, aligning with CI expectations.

@yungyuc yungyuc added the array Multi-dimensional array implementation label Mar 5, 2024
@yungyuc yungyuc changed the title SimpleArray caster issue Bad assembly with SimpleArray caster Mar 16, 2024
@yungyuc
Copy link
Member

yungyuc commented Apr 13, 2024

It's probably time to move forward with this issue. @tigercosmos could you please revisit it?

@tigercosmos
Copy link
Collaborator Author

It's probably time to move forward with this issue. @tigercosmos could you please revisit it?

sure, I will find some time to look at this.

@tigercosmos
Copy link
Collaborator Author

@yungyuc do you have any suggestions or hints?

@yungyuc
Copy link
Member

yungyuc commented Apr 14, 2024

I didn't study the problem myself. This seems to be a challenging one involving the interaction between pybind11, modmesh, and the compiler. At the time being, the workaround is to increase the optimization level for debug build. The workaround itself is a concern because the increased optimization level may reduce the details of the debug build.

I think the main focus is to remove the debug-with-optimization workaround. It matters less why the modmesh code leads to the issue. It is OK to change the modmesh C++ code as long as the workaround can be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array Multi-dimensional array implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants