[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:41:34 PDT 2021
whisperity created this revision.
whisperity added a reviewer: aaron.ballman.
whisperity added a project: clang-tools-extra.
Herald added subscribers: martong, gamesh411, Szelethus, dkrupp, rnkovacs, xazax.hun.
whisperity requested review of this revision.
Herald added a subscriber: cfe-commits.
Fixes #50995 <http://bugs.llvm.org/show_bug.cgi?id=50995>.
A(n otherwise unexercised) code path related to trying to model //"array-to-pointer decay"// resulted in a null pointer dereference crash when parameters of type //"reference to array"// are encountered.
The aforementioned code path is not needed, as cases when arrays //can// decay are already handled by the main function of the modelling routine when desugaring the `DecayedType`.
Repository:
rG LLVM Github Monorepo
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
@@ -383,3 +383,11 @@
void attributedParam4(const __attribute__((address_space(512))) int *One,
const __attribute__((address_space(256))) MyInt1 *Two) {}
// NO-WARN: Different value of the attribute.
+
+typedef int Point[2];
+
+void crefToArrayTypedef1(int I, const Point &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef2(int *IA, const Point &P) {}
+// NO-WARN.
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
@@ -303,3 +303,11 @@
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!
+
+typedef int Point[2];
+
+void crefToArrayTypedef1(int I, const Point &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef2(int *IA, const Point &P) {}
+// NO-WARN.
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.362324.patch
Type: text/x-patch
Size: 2474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210728/d09fd317/attachment.bin>
More information about the cfe-commits
mailing list