-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc][NFC] Fix missing LIBC_INLINE + style #73659
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,13 @@ | |
#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H | ||
|
||
#include "src/__support/CPP/type_traits/remove_reference.h" | ||
#include "src/__support/macros/attributes.h" // LIBC_INLINE | ||
|
||
namespace LIBC_NAMESPACE::cpp { | ||
|
||
// move | ||
template <class T> constexpr cpp::remove_reference_t<T> &&move(T &&t) { | ||
template <class T> | ||
LIBC_INLINE constexpr cpp::remove_reference_t<T> &&move(T &&t) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same: templates are implicitly inline |
||
return static_cast<typename cpp::remove_reference_t<T> &&>(t); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,10 @@ namespace LIBC_NAMESPACE { | |
LLVM_LIBC_FUNCTION(void *, memmem, | ||
(const void *haystack, size_t haystack_len, | ||
const void *needle, size_t needle_len)) { | ||
constexpr auto comp = [](unsigned char l, unsigned char r) -> int { | ||
constexpr auto COMP = [](unsigned char l, unsigned char r) -> int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change wanted ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, although it could be done as a separate PR. |
||
return l - r; | ||
}; | ||
return inline_memmem(haystack, haystack_len, needle, needle_len, comp); | ||
return inline_memmem(haystack, haystack_len, needle, needle_len, COMP); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
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.
This is already implied by the fact that the function is defined in the class declaration. @frobtech can we fix the clang -tidy to ignore this ?
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.
(also applies to pretty much all code in these files)
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.
This is a fundamental misunderstanding of the purpose of
LIBC_INLINE
. It is never implicit, because it exists to be (sometimes) defined to something other than simplyinline
.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.
I've read the documentation (libc/docs/code_style.rst), but it conflates
LIBC_INLINE
andinline
:(though it does mention implicitly inline functions):
I still kind of find the name misleading, maybe it should just avoid using
inline
which is already used for not-quite-the-same concept ?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.
The meaning is "where you'd use the
inline
keyword or it would be implied by the language spec", so I'm not at a loss for what different name would be more clear.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.
The
LIBC_INLINE
macro impliesinline
, but some of our users (specifically Fuchsia) redefine the macro themselves to ensure that inlined functions also have additional properties. In Fuchsia's case they use it to enforce internal linkage. Linked below is their definition, along with a comment explaining why this is necessary.https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/system/ulib/c/string/mem-aliases-include/src/__support/macros/attributes.h;l=24
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.
Thanks for the explanations. Can we put these in the doc (libc/docs/code_style.rst) ? There are probably going to be other people like me who are going to wonder about that, and those latter explanations make a lot of sense.
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.
As of today, the clang-tidy makes sure that
LIBC_INLINE
is in first position. This makes sense given Fuchsia' s definition but this makes it impossible to useLIBC_INLINE
functions with attributes: e.g.: