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


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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to