whisperity updated this revision to Diff 362333. whisperity added a comment.
Add some more test cases! 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; @@ -383,3 +403,4 @@ void attributedParam4(const __attribute__((address_space(512))) int *One, const __attribute__((address_space(256))) MyInt1 *Two) {} // NO-WARN: Different value of the attribute. + 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' @@ -303,3 +323,4 @@ void templateConversion(IntConverter IC, FloatConverter FC) { templateConversion(FC, IC); } // Note: even though this swap is possible, we do not model things when it comes to "template magic". // But at least the check should not crash! + 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
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; @@ -383,3 +403,4 @@ void attributedParam4(const __attribute__((address_space(512))) int *One, const __attribute__((address_space(256))) MyInt1 *Two) {} // NO-WARN: Different value of the attribute. + 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' @@ -303,3 +323,4 @@ void templateConversion(IntConverter IC, FloatConverter FC) { templateConversion(FC, IC); } // Note: even though this swap is possible, we do not model things when it comes to "template magic". // But at least the check should not crash! + 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits