Author: Congcong Cai Date: 2025-03-08T13:41:24+08:00 New Revision: 6f7570c200aa1ee9af9d1eb7a378d56264ee297e
URL: https://github.com/llvm/llvm-project/commit/6f7570c200aa1ee9af9d1eb7a378d56264ee297e DIFF: https://github.com/llvm/llvm-project/commit/6f7570c200aa1ee9af9d1eb7a378d56264ee297e.diff LOG: [clang-tidy][misc-use-internal-linkage] fix false positives for function or variable in header file which contains macro expansion (#129594) When check whether in main file, spelling loc will lead to `<scratch space>`. instead, expansion loc is close to loc after preprocess. It is suitable to analyze linkage. Added: clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp Modified: clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp index 4778182944abd..a1a20c0782230 100644 --- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp @@ -52,7 +52,7 @@ AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); } static bool isInMainFile(SourceLocation L, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions) { for (;;) { - if (utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions)) + if (utils::isExpansionLocInHeaderFile(L, SM, HeaderFileExtensions)) return false; if (SM.isInMainFile(L)) return true; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index ce1418a2a7d58..453617efaae26 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -129,6 +129,10 @@ Changes in existing checks <clang-tidy/checks/misc/redundant-expression>` check by providing additional examples and fixing some macro related false positives. +- Improved :doc:`misc-use-internal-linkage + <clang-tidy/checks/misc/use-internal-linkage>` check by fix false positives + for function or variable in header file which contains macro expansion. + - Improved :doc:`performance/unnecessary-value-param <clang-tidy/checks/performance/unnecessary-value-param>` check performance by tolerating fix-it breaking compilation when functions is used as pointers diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp new file mode 100644 index 0000000000000..209bd56028c3d --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp @@ -0,0 +1,5 @@ +// RUN: %check_clang_tidy %s misc-use-internal-linkage %t -- -- -I%S/Inputs/use-internal-linkage + +#define B A##C + +inline void B() {} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits