https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/69062
>From bfeaa2eeaa3d20e1919288bcf1027ec196378236 Mon Sep 17 00:00:00 2001 From: Congcong Cai <congcongcai0...@163.com> Date: Sun, 15 Oct 2023 00:20:08 +0800 Subject: [PATCH 1/2] [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType before resolve type size --- .../clang-tidy/modernize/LoopConvertCheck.cpp | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../clang-tidy/checkers/modernize/loop-convert-basic.cpp | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index f90d99a8d66069d..8beaa62c78ba0ab 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -753,6 +753,7 @@ void LoopConvertCheck::doConversion( bool IsCheapToCopy = !Descriptor.ElemType.isNull() && Descriptor.ElemType.isTriviallyCopyableType(*Context) && + !Descriptor.ElemType->isDependentSizedArrayType() && // TypeInfo::Width is in bits. Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize; bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) || diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 03e5dc6f164af2a..ae440210d8a4f2b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -269,6 +269,10 @@ Changes in existing checks <clang-tidy/checks/modernize/loop-convert>` to support for-loops with iterators initialized by free functions like ``begin``, ``end``, or ``size``. +- Improved :doc:`modernize-loop-convert + <clang-tidy/checks/modernize/loop-convert>` to avoid crash dor dependent + array. + - Improved :doc:`modernize-return-braced-init-list <clang-tidy/checks/modernize/return-braced-init-list>` check to ignore false-positives when constructing the container with ``count`` copies of diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp index 71ae4c46e6a5e95..8d8144a729bbdee 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp @@ -939,4 +939,13 @@ void fundamentalTypesTest() { // CHECK-FIXES: for (double Double : Doubles) } +template <unsigned int p> void test() { + unsigned int test[3][p]; + // Initialize to zero + for (unsigned int i = 0; i < p; ++i) + for (unsigned int j = 0; j < 3; ++j) // CHECK-MESSAGES: warning: use range-based for loop instead + // CHECK-FIXES: (auto & j : test) + test[j][i] = 0; +} + } // namespace PseudoArray >From 89ddc2510e74b7b7460384860ce691a6784fa82b Mon Sep 17 00:00:00 2001 From: Congcong Cai <congcongcai0...@163.com> Date: Sun, 15 Oct 2023 09:42:33 +0800 Subject: [PATCH 2/2] fix --- clang-tools-extra/docs/ReleaseNotes.rst | 7 ++----- .../clang-tidy/checkers/modernize/loop-convert-basic.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index ae440210d8a4f2b..63f9a2418eca5aa 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -267,11 +267,8 @@ Changes in existing checks - Improved :doc:`modernize-loop-convert <clang-tidy/checks/modernize/loop-convert>` to support for-loops with - iterators initialized by free functions like ``begin``, ``end``, or ``size``. - -- Improved :doc:`modernize-loop-convert - <clang-tidy/checks/modernize/loop-convert>` to avoid crash dor dependent - array. + iterators initialized by free functions like ``begin``, ``end``, or ``size`` + and avoid crash for array of dependent array. - Improved :doc:`modernize-return-braced-init-list <clang-tidy/checks/modernize/return-braced-init-list>` check to ignore diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp index 8d8144a729bbdee..2e43bc6ff96e4e5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp @@ -943,9 +943,11 @@ template <unsigned int p> void test() { unsigned int test[3][p]; // Initialize to zero for (unsigned int i = 0; i < p; ++i) - for (unsigned int j = 0; j < 3; ++j) // CHECK-MESSAGES: warning: use range-based for loop instead - // CHECK-FIXES: (auto & j : test) + for (unsigned int j = 0; j < 3; ++j) test[j][i] = 0; + // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead + // CHECK-FIXES: (auto & j : test) + // CHECK-FIXES: j[i] = 0; } } // namespace PseudoArray _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits