NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
511 stars 183 forks source link

Enable more strict dynamic cast checks #1873

Open bettinaheim opened 4 months ago

bettinaheim commented 4 months ago

When adding support for libc++, I needed to configure the LLVM build to enable more permissive dynamic casts, that fall back to string comparison and accept the cast despite differences in the static definitions. While this is the default behavior with gcc, the fact that we clearly rely on this could cause hard to debug problems. I think most likely, we have class definitions for the simulator states that are in header files, causing potential ambiguity in the dynamic casting. I think we need to make a pass over the code base more generally to more carefully examine our header files and reduce them to declarations only to avoid potential compatibility issues. For anything that is defined in a header file, it should be save to compile it with a different toolchain than CUDA-Q and still work the same way when linked together with pre-built CUDA-Q libraries.

schweitzpgi commented 4 months ago

What was the option that you needed to add?

schweitzpgi commented 3 months ago

My guess is that this is a case of multiple C++ support library implementations somehow leaking into the binary. The dyn_cast in C++ uses RTTI. RTTI and dyn_cast RTTI is not portable and the standard doesn't define its implementation. RTTI not portable

While I think the intention is that this not be the case, I suspect somehow that it is happening and this is the reason why the dyn_cast are failing.

Not really a build problem per se, other than the build is possibly using multiple compilers and/or runtimes at different steps and that is leading to these sorts of problems. The obvious fix is "don't do that", which is easier said than done.