[clang-tools-extra] [clang-tidy][libc] Ignore implicit function inline (PR #71095)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 12:34:25 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tidy

Author: None (michaelrj-google)

<details>
<summary>Changes</summary>

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.


---
Full diff: https://github.com/llvm/llvm-project/pull/71095.diff


4 Files Affected:

- (modified) clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp (+4) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst (+4-3) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp (+11) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/71095


More information about the cfe-commits mailing list