-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[libc++] ordering comparisons should be marked __attribute__((pure)) #62022
Comments
Clang generates warnings even if those comparisons are pure: llvm/llvm-project#62022
I don't think we want to do this. This isn't an ABI boundary, so we shouldn't have to annotate it. This would also set a precedent of annotating inline functions with |
I agree clang should do this. Right now it's not possible to compare non-primitive types in __builtin_assume(). Is there some pragmatic middle ground that could allow comparisons in __builtin_assume() until Clang improves things? Is there some line we could draw between "all pure functions" and basic operations like comparison? |
Clang generates warnings even if those comparisons are pure: llvm/llvm-project#62022
I don't think there is a clear defensible line anywhere other than "we don't do it anywhere" and "we mark all the pure functions as |
@llvm/issue-subscribers-clang-frontend |
Clang generates warnings even if those comparisons are pure: llvm/llvm-project#62022
Clang generates warnings even if those comparisons are pure: llvm/llvm-project#62022
Besides "massive effort", what would be the arguments against "[[gnu::pure/const]] everything applicable"? Unnecessary ABI break? Risk of subtle bugs in the future if one becomes non-pure/const but attribute isn't removed? Is it possible to guesstimate the potential benefit of such a change from the optimization side? Or would fewer false-positive warnings be the primary benefit? |
Possible answers to my own question:
|
This isn't an ABI break. My main concerns are that it will introduce very hard to find bugs without much of a benefit, as well as not having a clear line where to put these attributes. There doesn't seem to be any benefit to optimizations, since the compiler always has visibility into the implementation of the functions (we already use these attributes for functions that are in the dylib). AFAICT the only benefit to add these attributes is to avoid warnings with |
In theory, the compiler having visibility into the implementation seems
like it should make these provide no optimization benefit. Is that known to
be true in practice? Or is it plausible these could provide meaningful
hints to the compiler in any cases?
Context for all these questions: was discussing trying to find code in
chromium which has side effects inside the invocation of a particular
macro, and someone noted that the lack of these situations on the library
APIs might make it difficult to avoid false positives.
…On Mon, Jan 29, 2024, 10:37 AM Nikolas Klauser ***@***.***> wrote:
Besides "massive effort", what would be the arguments against
"[[gnu::pure/const]] everything applicable"? Unnecessary ABI break? Risk of
subtle bugs in the future if one becomes non-pure/const but attribute isn't
removed?
Is it possible to guesstimate the potential benefit of such a change from
the optimization side? Or would fewer false-positive warnings be the
primary benefit?
This isn't an ABI break. My main concerns are that it will introduce very
hard to find bugs without much of a benefit, as well as not having a clear
line where to put these attributes. There doesn't seem to be any benefit to
optimizations, since the compiler always has visibility into the
implementation of the functions (we already use these attributes for
functions that are in the dylib). AFAICT the only benefit to add these
attributes is to avoid warnings with __builtin_assume, which makes this a
very high risk undertaking with quite low rewards.
—
Reply to this email directly, view it on GitHub
<#62022 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADGSAF5CQEFS3GTIVXTPZ7TYQ7T7BAVCNFSM6AAAAAAWXVLKUOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJVGMZTMNBRGI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
It's quite hard to prove a negative, but there is the
You can easily do that by implementing your check as a pass and run the pass mentioned above before. It's not likely super pretty, but it should get the job done. |
https://godbolt.org/z/e4rTvMeoW
The following code generates
-Wassume
warnings suggesting there are side effects when converting from astrong_ordering
to abool
. The same is true ofpartial_ordering
andweak_ordering
.I tried to find the right place to insert
__attribute__((pure))
. I think all of these:llvm-project/libcxx/include/__compare/ordering.h
Lines 157 to 213 in e3d2b58
llvm-project/libcxx/include/__compare/ordering.h
Lines 72 to 129 in e3d2b58
llvm-project/libcxx/include/__compare/ordering.h
Lines 249 to 305 in e3d2b58
The text was updated successfully, but these errors were encountered: