https://github.com/berkaysahiin updated https://github.com/llvm/llvm-project/pull/186607
>From d5a32e47e54a02783ebb2a584b4b81b3328e395c Mon Sep 17 00:00:00 2001 From: Berkay <[email protected]> Date: Sat, 14 Mar 2026 20:22:39 +0300 Subject: [PATCH 1/5] [clang-tidy] Adds do-while support to performance-inefficient-string-concatenation --- .../InefficientStringConcatenationCheck.cpp | 10 +++++----- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../performance/inefficient-string-concatenation.rst | 2 +- .../performance/inefficient-string-concatenation.cpp | 6 ++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp index 92e3220fdb817..1067fca289a2c 100644 --- a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp @@ -53,11 +53,11 @@ void InefficientStringConcatenationCheck::registerMatchers( Finder->addMatcher(cxxOperatorCallExpr(anyOf(AssignOperator, PlusOperator)), this); } else { - Finder->addMatcher( - cxxOperatorCallExpr(anyOf(AssignOperator, PlusOperator), - hasAncestor(stmt(anyOf(cxxForRangeStmt(), - whileStmt(), forStmt())))), - this); + Finder->addMatcher(cxxOperatorCallExpr(anyOf(AssignOperator, PlusOperator), + hasAncestor(stmt(anyOf( + cxxForRangeStmt(), whileStmt(), + forStmt(), doStmt())))), + this); } } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 4b207609d598d..a3714736aa988 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -315,6 +315,10 @@ Changes in existing checks - Fixes false negatives when using ``std::set`` from ``libstdc++``. +- Improved :doc:`performance-inefficient-string-concatenation + <clang-tidy/checks/performance/performance-inefficient-string-concatenation>` check by + adding support for detecting inefficient string concatenation in ``do-while`` loops. + - Improved :doc:`performance-inefficient-vector-operation <clang-tidy/checks/performance/inefficient-vector-operation>` check by correctly handling vector-like classes when ``push_back``/``emplace_back`` are diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst b/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst index 92b6b4e0370d6..1dacf91389154 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst @@ -55,5 +55,5 @@ Options .. option:: StrictMode - When `false`, the check will only check the string usage in ``while``, ``for`` + When `false`, the check will only check the string usage in ``while``, ``do-while``, ``for`` and ``for-range`` statements. Default is `false`. diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp index 72080ed39e59b..adc37e4c4bedf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp @@ -32,5 +32,11 @@ int main() { f(mystr2 + mystr1); mystr1 = g(mystr1); } + + do { + mystr1 = mystr1 + mystr2; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead + } while (0); + return 0; } >From bdb55a574c2d4f3d820e1cff57efaf0f7530db20 Mon Sep 17 00:00:00 2001 From: Berkay <[email protected]> Date: Sat, 14 Mar 2026 20:45:50 +0300 Subject: [PATCH 2/5] [clang-tidy] Fix typo in the release note entry --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index a3714736aa988..cc7418b973277 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -316,7 +316,7 @@ Changes in existing checks - Fixes false negatives when using ``std::set`` from ``libstdc++``. - Improved :doc:`performance-inefficient-string-concatenation - <clang-tidy/checks/performance/performance-inefficient-string-concatenation>` check by + <clang-tidy/checks/performance/inefficient-string-concatenation>` check by adding support for detecting inefficient string concatenation in ``do-while`` loops. - Improved :doc:`performance-inefficient-vector-operation >From 57a379d0625d87faaa07713552371bb89e7db439 Mon Sep 17 00:00:00 2001 From: Berkay Sahin <[email protected]> Date: Sat, 14 Mar 2026 20:57:29 +0300 Subject: [PATCH 3/5] Update clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst Co-authored-by: Victor Chernyakin <[email protected]> --- .../checks/performance/inefficient-string-concatenation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst b/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst index 1dacf91389154..56f6b9640080d 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst @@ -55,5 +55,5 @@ Options .. option:: StrictMode - When `false`, the check will only check the string usage in ``while``, ``do-while``, ``for`` - and ``for-range`` statements. Default is `false`. + When `false`, the check will only warn on inefficient string usage inside loops. + Default is `false`. >From d465ae5b0e0a290bce349472f150d46352eae281 Mon Sep 17 00:00:00 2001 From: Berkay <[email protected]> Date: Sat, 14 Mar 2026 21:02:56 +0300 Subject: [PATCH 4/5] [clang-tidy] Fix spacing in the release note entry --- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index cc7418b973277..64b0d3afb914c 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -316,8 +316,8 @@ Changes in existing checks - Fixes false negatives when using ``std::set`` from ``libstdc++``. - Improved :doc:`performance-inefficient-string-concatenation - <clang-tidy/checks/performance/inefficient-string-concatenation>` check by - adding support for detecting inefficient string concatenation in ``do-while`` loops. + <clang-tidy/checks/performance/inefficient-string-concatenation>` check by + adding support for detecting inefficient string concatenation in ``do-while`` loops. - Improved :doc:`performance-inefficient-vector-operation <clang-tidy/checks/performance/inefficient-vector-operation>` check by >From 99c0ed7c4f394c8fa2d7b39f24867dfd4273e5b6 Mon Sep 17 00:00:00 2001 From: Berkay Sahin <[email protected]> Date: Sun, 15 Mar 2026 13:56:42 +0300 Subject: [PATCH 5/5] Update clang-tools-extra/docs/ReleaseNotes.rst Co-authored-by: EugeneZelenko <[email protected]> --- clang-tools-extra/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 64b0d3afb914c..f8de97e194e57 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -317,7 +317,8 @@ Changes in existing checks - Improved :doc:`performance-inefficient-string-concatenation <clang-tidy/checks/performance/inefficient-string-concatenation>` check by - adding support for detecting inefficient string concatenation in ``do-while`` loops. + adding support for detecting inefficient string concatenation in ``do-while`` + loops. - Improved :doc:`performance-inefficient-vector-operation <clang-tidy/checks/performance/inefficient-vector-operation>` check by _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
