[PATCH] D106946: [clang-tidy] Fix crash on "reference to array" parameters in 'bugprone-easily-swappable-parameters'
Whisperity via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 28 04:43:39 PDT 2021
whisperity updated this revision to Diff 362334.
whisperity added a comment.
**NFC** //Typo-fix//: Remove empty line from end of diff.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106946/new/
https://reviews.llvm.org/D106946
Files:
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
@@ -244,6 +244,26 @@
// CHECK-MESSAGES: :[[@LINE-6]]:52: note: 'int' and 'MyIntCRTy' parameters accept and bind the same kind of values
// CHECK-MESSAGES: :[[@LINE-7]]:37: note: after resolving type aliases, the common type of 'ICRTy' and 'MyIntCRTy' is 'const int &'
+typedef int Point2D[2];
+typedef int Point3D[3];
+
+void arrays1(Point2D P2D, Point3D P3D) {} // In reality this is (int*, int*).
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 'arrays1' of similar type ('int *') are
+// CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'P2D'
+// CHECK-MESSAGES: :[[@LINE-3]]:35: note: the last parameter in the range is 'P3D'
+
+void crefToArrayTypedef1(int I, const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef2(int *IA, const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef3(int P1[2], const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedefBoth1(const Point2D &VecDescartes, const Point3D &VecThreeD) {}
+// NO-WARN: Distinct types and no conversion because of &.
+
short const typedef int unsigned Eldritch;
typedef const unsigned short Holy;
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
@@ -26,6 +26,26 @@
void arrayAndElement(int I, int IA[]) {} // NO-WARN.
+typedef int Point2D[2];
+typedef int Point3D[3];
+
+void arrays1(Point2D P2D, Point3D P3D) {} // In reality this is (int*, int*).
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 'arrays1' of similar type ('int *') are
+// CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'P2D'
+// CHECK-MESSAGES: :[[@LINE-3]]:35: note: the last parameter in the range is 'P3D'
+
+void crefToArrayTypedef1(int I, const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef2(int *IA, const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef3(int P1[2], const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedefBoth1(const Point2D &VecDescartes, const Point3D &VecThreeD) {}
+// NO-WARN: Distinct types.
+
void numericConversion1(int I, double D) { numericConversion1(D, I); }
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion1' of convertible types are easily swapped by mistake [bugprone-easily-swappable-parameters]
// CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
Index: clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -962,11 +962,8 @@
// LValue->RValue is irrelevant for the check, because it is a thing to be
// done at a call site, and will be performed if need be performed.
- // Array->Ptr decay.
- if (const auto *ArrayT = dyn_cast<ArrayType>(From)) {
- LLVM_DEBUG(llvm::dbgs() << "--- approximateStdConv. Array->Ptr decayed.\n");
- WorkType = ArrayT->getPointeeType();
- }
+ // Array->Pointer decay is handled by the main method in desugaring
+ // the parameter's DecayedType as "useless sugar".
// Function->Pointer conversions are also irrelevant, because a
// "FunctionType" cannot be the type of a parameter variable, so this
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106946.362334.patch
Type: text/x-patch
Size: 3955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210728/2f8544dc/attachment.bin>
More information about the cfe-commits
mailing list