Author: Joseph Huber Date: 2023-04-16T10:58:44-05:00 New Revision: 1663016b41d71a60f3d268607c6fbf16fcf85172
URL: https://github.com/llvm/llvm-project/commit/1663016b41d71a60f3d268607c6fbf16fcf85172 DIFF: https://github.com/llvm/llvm-project/commit/1663016b41d71a60f3d268607c6fbf16fcf85172.diff LOG: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas The `llvmlibc-inline-function-decl` check is intended to be used to allow declarations in the `libc` project's header to be changed per-TU. However, it is impossible to place this macro in front of a lambda so this is not helpful. Additionally, lambdas are always going to have internal linkage so they will not differ accross TUs. Fixes https://github.com/llvm/llvm-project/issues/62147 Reviewed By: lntue, PiotrZSL Differential Revision: https://reviews.llvm.org/D148444 Added: Modified: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp index 803e32da5279..fa643a138792 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp @@ -39,6 +39,12 @@ void InlineFunctionDeclCheck::check(const MatchFinder::MatchResult &Result) { HeaderFileExtensions)) return; + // Ignore lambda functions as they are internal and implicit. + if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl)) { + if (MethodDecl->getParent()->isLambda()) + return; + } + // Check if decl starts with LIBC_INLINE auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin), *Result.SourceManager); 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 b59c2d20be05..24d0441742a7 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 @@ -60,6 +60,14 @@ class MyClass { } }; +LIBC_INLINE void lambda() { +// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] + [](){}; +} + } // namespace __llvm_libc #endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits