-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[clang-tidy][libc] Ignore implicit function inline #71095
Conversation
This patch adjusts the inline function decl check for LLVM libc to ignore implicit functions. For the moment the plan is to ignore these and mark the class with a macro so that it can be given the appropriate properties without explicitly defining all its ctors/dtors.
@llvm/pr-subscribers-clang-tidy Author: None (michaelrj-google) ChangesThis patch adjusts the inline function decl check for LLVM libc to Full diff: https://github.com/llvm/llvm-project/pull/71095.diff 4 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
index c119e393d3ab692..7f51d0b8c51e7f4 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -79,6 +79,10 @@ void InlineFunctionDeclCheck::check(const MatchFinder::MatchResult &Result) {
if (MethodDecl->getParent()->isLambda())
return;
+ // Ignore implicit functions (e.g. implicit constructors or destructors)
+ if (FuncDecl->isImplicit())
+ return;
+
// Check if decl starts with LIBC_INLINE
auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index ecfb3aa9267f140..c47a73b022037d9 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -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.
+
- Improved :doc:`misc-const-correctness
<clang-tidy/checks/misc/const-correctness>` check to avoid false positive when
using pointer to member function.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst
index 101217b64c82852..87beb628ac91985 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst
@@ -3,6 +3,7 @@
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.
+See the `libc style guide<https://libc.llvm.org/dev/code_style.html>`_ for more
+information about this macro.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
index 0028c575b1d6871..b2a67a08d0b0d69 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -278,6 +278,17 @@ 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>();
+
} // namespace issue_62746
} // namespace __llvm_libc
|
clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
Outdated
Show resolved
Hide resolved
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,
Consider also adding tests for default and deleted constructors or assign operators, I think that they also could generate false-positive.
<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. | ||
See the `libc style guide<https://libc.llvm.org/dev/code_style.html>`_ for more |
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.
There is some documentation error on this line, maybe some space is missing before <
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 added the space, hopefully it is happy now.
Also add tests for defaulted and deleted functions
This patch adjusts the inline function decl check for LLVM libc to
ignore implicit functions. For the moment the plan is to ignore these
and mark the class with a macro so that it can be given the appropriate
properties without explicitly defining all its ctors/dtors.