-
Notifications
You must be signed in to change notification settings - Fork 231
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
[BUG] MSVC does not optimize out the lambda created by the CPP2_UFCS macros. #185
Comments
|
I didn't check that, and this is really helpful, thanks. I think there is something I can do about this... I just googled around and found this StackOverflow answer quoting Jonathan Caves' answer of using I'll try that and check that it passes regression testing in GCC and Clang... they should just ignore the attribute, but if they don't I'll need to hide it behind YAM (yet another macro). Thanks! |
|
Update: As in that SO answer, GCC and Clang want |
|
@hsutter I did try |
|
It didn't get rid of the lambda sitting in the object image (MSVC still isn't as good as other compilers at not displaying unreachable code under Godbolt CE) but the lambda is never called in Try this slight variation https://godbolt.org/z/459sMx9n4 which shows it as two functions that differ only in direct call vs. UFCS: On all three compilers at Interesting thing: On Thanks again for pointing it out! |
|
I see great, thanks for the explanation I was just looking for the lambda in the assembly :) The godbolt link you shared does look like what I'd expect (minus the lambda which is now dead code). |
Describe the bug
As the title describe, MSVC 19 doesn't optimize out the UFCS macros. It seems to be a serious problem since the UFCS lambdas generate a fair bit of code and end up generated for every function call. Both GCC & Clang optimize them out even at the lowest optimization level (-Og).
This is not a bug in cppfront per say, but it is still a bug that will affect it directly imo - and maybe something that cppfront can work around. It is not clear where it should be fixed ultimately.
To Reproduce
https://godbolt.org/z/ravPdfjoG
Additional context
I was playing with the UFCS macros in regular C++ code and I wanted to see whether the lambdas got removed in debug builds, put them in godbolt, no compilers get rid of them with -O0 - which is understandable. GCC & Clang get rid of them at any optimization level I tried (-Og, -Os, -O1, -O2) but MSVC doesnt even get rid of them in any optimization level (neither /O2 nor /O3 - although I dont recall whether that's a legit level for MSVC or if it just gets pegged back to /O2).
The text was updated successfully, but these errors were encountered: