-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc++] std::deque loops over the deque for ASAN even when annotations are disabled #73043
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
Comments
We rely here on compiler optimizations. The loop comprises no-op operations and is thus expected to be eliminated during the optimization process. That this optimization can happez can be confirmed by examining the assembly code. When compiled with the -O1 flag, LLVM16 and LLVM17 produce identical output. This code also iterates over modified chunks only (not even elements), so it should never impact complexity. When one object is added/removed and annotations are not optimized-out, the loop is executed only once. It should also affect only programs without optimizations (-O0) in any way. When compiled without optimizations (-O0), based on one oversimplified benchmark I was able to run, the performance impact of this code is negligible. (I compared the performance of LLVM16 and LLVM17.) However, that amount of additional code with -O0 is not desirable, I can prepare a patch on Monday minimizing it (but not fully removing). But should I do the same for the std::vector container? While vector adds much less calculations, the logic is the same: The rationale behind maintaining a single set of functions and relying on compiler optimizations lies in the avoidance of redundant code maintenance and minimization of conditional code guarded by #ifdef directives. These optimizations are relatively straightforward, and I anticipate encountering no instances where annotations persist during optimization. In summary, I propose retaining the current implementation unless there are instances where these functions fail to undergo optimization. However, I acknowledge that |
Thanks a lot for your analysis. Would it be possible to do this instead?
The same approach could be done for |
I wasn't aware that That should work. I can test it and create the PR (Monday at the latest). I agree it's reasonable. I will do it in deque and vector (and string PR) for functions with two versions, as well as If you think that we should do that for every |
Hey, I created #74023 based on suggestion from discord ( |
This commit refactors the ASan annotation functions in libc++ to improve code maintainability and reduce unnecessary code duplication. - Eliminates two redundant function versions by utilizing the [[maybe_unused]] attribute and guarding function bodies with #ifndef _LIBCPP_HAS_NO_ASAN. - Introduces an additional guard to an auxiliary function, allowing the removal of a no-ops function body. This approach avoids relying on the optimizer for code elimination. Suggested by @ldionne in llvm#73043
This commit refactors the ASan annotation functions in libc++ to reduce unnecessary code duplication. Additionally it adds a small optimization. - Eliminates two redundant function versions by utilizing the `[[maybe_unused]]` attribute and guarding function bodies with `#ifndef _LIBCPP_HAS_NO_ASAN`. - Introduces an additional guard to an auxiliary function, allowing the removal of a no-ops function body. This approach avoids relying on the optimizer for code elimination. Fixes #73043
This commit refactors the ASan annotation function to reduce unnecessary code duplication. Suggested here: llvm#73043 Related PR: llvm#74023
This seems unintended: https://github.com/llvm/llvm-project/blob/main/libcxx/include/deque#L987
The text was updated successfully, but these errors were encountered: