[clang-tools-extra] 5ae5af1 - [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (#69062)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 15 18:02:59 PDT 2023
Author: Congcong Cai
Date: 2023-10-16T09:02:53+08:00
New Revision: 5ae5af1d7c60ac10d91573d251c2d81083cd6ada
URL: https://github.com/llvm/llvm-project/commit/5ae5af1d7c60ac10d91573d251c2d81083cd6ada
DIFF: https://github.com/llvm/llvm-project/commit/5ae5af1d7c60ac10d91573d251c2d81083cd6ada.diff
LOG: [clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (#69062)
Added:
Modified:
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
Removed:
################################################################################
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 c732d4904df13fa..af164d0462d52c1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -271,7 +271,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``.
+ 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 71ae4c46e6a5e95..e2b9336d620f507 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,18 @@ void fundamentalTypesTest() {
// CHECK-FIXES: for (double Double : Doubles)
}
+template <unsigned p> void _dependenceArrayTest() {
+ unsigned test[3][p];
+ for (unsigned i = 0; i < p; ++i)
+ for (unsigned j = 0; j < 3; ++j)
+ printf("%d", test[j][i]);
+ // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
+ // CHECK-FIXES: (auto & j : test)
+ // CHECK-FIXES: printf("%d", j[i]);
+}
+void dependenceArrayTest() {
+ _dependenceArrayTest<1>();
+ _dependenceArrayTest<2>();
+}
+
} // namespace PseudoArray
More information about the cfe-commits
mailing list