-
Notifications
You must be signed in to change notification settings - Fork 15k
[libc] don't over include stdlib in the hdr declaring bsearch #89471
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
Conversation
When building overlay mode with GCC in release mode, glibc's stdlib.h contains an extern inline declaration of bsearch. This breaks our use of the gnu::alias function attribute in LLVM_LIBC_FUNCTION with GCC because GCC checks that the aliasee is defined in the same TU (clang does not). We're looking at also potentially updating our definition of LLVM_LIBC_FUNCTION from libc/src/__support/common.h. Upon testing, I was able to get -Wnonnull-compare diagnostics from GCC in our definition of bsearch because glibc declares bsearch with the fugly nonnull function attribute. There's more we can do here though to improve our implementation of bsearch. 7.24.5.1 says: Pointer arguments on such a call shall still have valid values, as described in 7.1.4. We could also use either function attributes or parameter attributes to denote these should not be null (for users/callers) and perhaps still check for non-null explicitly under some yet to be discussed hardening configurations in the future. Fixes: llvm#60481 Link: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-nonnull-function-attribute
@llvm/pr-subscribers-libc Author: Nick Desaulniers (nickdesaulniers) ChangesWhen building overlay mode with GCC in release mode, glibc's stdlib.h contains We're looking at also potentially updating our definition of LLVM_LIBC_FUNCTION There's more we can do here though to improve our implementation of bsearch.
We could also use either function attributes or parameter attributes to denote Fixes: #60481 Full diff: https://github.com/llvm/llvm-project/pull/89471.diff 1 Files Affected:
diff --git a/libc/src/stdlib/bsearch.h b/libc/src/stdlib/bsearch.h
index 1de7e051ff6c41..3590198ba55704 100644
--- a/libc/src/stdlib/bsearch.h
+++ b/libc/src/stdlib/bsearch.h
@@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC_STDLIB_BSEARCH_H
#define LLVM_LIBC_SRC_STDLIB_BSEARCH_H
-#include <stdlib.h>
+#include <stddef.h> // size_t
namespace LIBC_NAMESPACE {
|
cc @enh-google |
Probably worth noting that similarly other issues may arise like this for functions other than bsearch. I did only test |
yeah |
maybe interesting. I'll think harder about it next week. |
interestingly, it looks like bionic and glibc disagree on the nullability? bionic has
iirc we went with a non-null base, but found too much code that felt that that should be fine as long as nmemb is 0 (and our implementation was fine with that anyway). |
(changed fixes tag to link tag), since those 3 other issues are more complex to resolve & might necessitate the changes to |
careful what you wish for anyway... they're likely to go with standardizing something you don't want, either because it's too strict and breaks code you need to support, or not strict enough (to not break anyone's code, including code you don't need to support). #include my usual "i'm not sure one size actually fits all" :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Filed #89474 against clang. |
When building overlay mode with GCC in release mode, glibc's stdlib.h contains
an extern inline declaration of bsearch. This breaks our use of the gnu::alias
function attribute in LLVM_LIBC_FUNCTION with GCC because GCC checks that the
aliasee is defined in the same TU (clang does not).
We're looking at also potentially updating our definition of LLVM_LIBC_FUNCTION
from libc/src/__support/common.h. Upon testing, I was able to get
-Wnonnull-compare diagnostics from GCC in our definition of bsearch because
glibc declares bsearch with the fugly nonnull function attribute.
There's more we can do here though to improve our implementation of bsearch.
7.24.5.1 says:
We could also use either function attributes or parameter attributes to denote
these should not be null (for users/callers) and perhaps still check for
non-null explicitly under some yet to be discussed hardening configurations in
the future.
Link: #60481
Link: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-nonnull-function-attribute