https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/71095
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. >From 0ca1191c2235881493a82f040c437d8da8a82862 Mon Sep 17 00:00:00 2001 From: Michael Jones <michae...@google.com> Date: Thu, 2 Nov 2023 12:23:34 -0700 Subject: [PATCH] [clang-tidy][libc] Ignore implicit function inline 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. --- .../clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp | 4 ++++ clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../checks/llvmlibc/inline-function-decl.rst | 7 ++++--- .../checkers/llvmlibc/inline-function-decl.hpp | 11 +++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits