Skip to content

[clang-tidy][libc] Ignore implicit function inline #71095

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ InlineFunctionDeclCheck::InlineFunctionDeclCheck(StringRef Name,
HeaderFileExtensions(Context->getHeaderFileExtensions()) {}

void InlineFunctionDeclCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(decl(functionDecl()).bind("func_decl"), this);
// Ignore functions that have been deleted.
Finder->addMatcher(decl(functionDecl(unless(isDeleted()))).bind("func_decl"),
this);
}

void InlineFunctionDeclCheck::check(const MatchFinder::MatchResult &Result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class InlineFunctionDeclCheck : public ClangTidyCheck {
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

// Ignore implicit functions (e.g. implicit constructors or destructors)
std::optional<TraversalKind> getCheckTraversalKind() const override {
return TK_IgnoreUnlessSpelledInSource;
}

private:
FileExtensionsSet HeaderFileExtensions;
};
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ Changes in existing checks
customizable namespace. This further allows for testing the libc when the
system-libc is also LLVM's libc.

- Improved :doc:`llvmlibc-inline-function-decl
<clang-tidy/checks/llvmlibc/inline-function-decl>` to properly ignore implicit
functions, such as struct constructors, and explicitly deleted functions.

- Improved :doc:`misc-const-correctness
<clang-tidy/checks/misc/const-correctness>` check to avoid false positive when
using pointer to member function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
llvmlibc-inline-function-decl
=============================

Checks that all implicit and explicit inline functions in header files are
tagged with the ``LIBC_INLINE`` macro. See the `libc style guide
<https://libc.llvm.org/dev/code_style.html>`_ for more information about this macro.
Checks that all implicitly and explicitly inline functions in header files are
tagged with the ``LIBC_INLINE`` macro, except for functions implicit to classes
or deleted functions.
See the `libc style guide <https://libc.llvm.org/dev/code_style.html>`_ for more
information about this macro.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,28 @@ template <typename T>LIBC_INLINE void goodWeirdFormatting() {}
template <typename T>void LIBC_INLINE badWeirdFormatting() {}
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'badWeirdFormatting' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]


template <unsigned int NumberOfBits> struct HasMemberAndTemplate {
char Data[NumberOfBits];

void explicitFunction() {}
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'explicitFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
// CHECK-FIXES: LIBC_INLINE void explicitFunction() {}
};

static auto instanceOfStruct = HasMemberAndTemplate<16>();

struct HasMemberAndExplicitDefault {
int TrivialMember;

HasMemberAndExplicitDefault() = default;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'HasMemberAndExplicitDefault' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
// CHECK-FIXES: LIBC_INLINE HasMemberAndExplicitDefault() = default;

~HasMemberAndExplicitDefault() = delete;
};


} // namespace issue_62746

} // namespace __llvm_libc
Expand Down