-
Notifications
You must be signed in to change notification settings - Fork 108
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
Broken Interconnect on Clang-CL 16.0.5 #178
Comments
Hi, thanks for the report! For MSVC I'm adding That's useful in general, especially in template-heavy code, where a lot of different template instantiations may end up being the exact same machine code, just with different types in C++. But for signals, which are distinguished from each other by the value of their function pointer, this is a problem -- let's say, I suppose clang-cl is doing something similar possibly, although I'm not aware of this problem on Linux or other platforms. Thus maybe clang-cl is using the MSVC linker and not its own, effectively inheriting the ICF optimization from it? So maybe using Depending on whether you use Corrade as a CMake subproject or externally installed, it'd mean expanding the logic to add Just for the full picture -- something similar is happening on GCC with It's quite a mess frankly, each new compiler version and every improvement to any optimizer being potentially breaking to this functionality. There are other signal/slot libraries based on the same principle (taking a pointer of the signal function to map them to slots) and all of them are running into the exact same issues. Libraries that don't, such as Qt, have some meta-compiler that circumvents this, but that was exactly the extra complexity I didn't want to deal with. On the other hand, the meta-compiler has the advantage that it can assign unique contiguous indices to the signals, making their lookup significantly faster than with a hashmap. Maybe something like embedding a compile-time-hashed value of the |
Yes, I'm already using I also tried to insert I like Interconnect because I can define new events very easily. I would like to avoid taking extra steps to define an event. |
Yeah, I suspect that made the optimizer exclude the function from optimization / merging / folding. Same was happening for me with the broken inline behavior, adding a printf statement made the problem go away. I'm not on Windows but I tried to reproduce the issue on the CI, and indeed the tests broke when I switched to
Yes, that's exactly why I made the library, because the design seemed very easy to use in theory. But then compilers happened :D |
I tried it again, rebuilt everything and it still doesn't work with |
Ah well. Are you able to reproduce with Corrade's own tests? Enable them with I tried on the CI with |
Yeah, all tests in |
Would you be able to create a minimal repro case I could look at, or change the test in a way that makes it fail too? Do you use any extra compiler or linker flags besides the CMake defaults for Release? There's also one other test that checks sending signals across DLLs, in case a variant of that scenario in particular is what could trigger this behavior. If everything else fails, I'll go with your original |
I discovered that if I disable exceptions completely (because I have it disabled in my project), following test starts to fail. And
|
Even though the C++ standard says that two pointers to the same function must compare equal, in practice this isn't possible to implement on all platforms - for example, on Windows with imported DLL functions, the first time the function is called might patch the function address, and if you take the address before and after they won't compare equal. I'm not sure how relevant this is to you, but I recommend being careful when it comes to comparing function pointers. |
Hi!
I'm using
Interconnect
classes and it works good in MSVC, but it seems there is some problem in Clang-CL (16.0.5, in VS 2022 17.7.4). If I build project in Release with optimizations turned on (any of /O2, /O1, /Ox), some signals (using member functions) don't connect correctly (so no events are triggered on them). I was able to fix it by adding__attribute__((optnone))
to this line: https://github.com/mosra/corrade/blob/master/src/Corrade/Interconnect/Connection.h#L59, so it seems the compiler probably somehow breaks theSignalData
constructor during optimizations. After the fix, it seems all signals work good, but I don't know why this happens and I couldn't find anything about it in the documentation. Do you have any idea? Also, I don't know which compilers are affected, I tested it only on MSVC and Clang-CL.The text was updated successfully, but these errors were encountered: