[PATCH] D135495: [clang-tidy] handle pointers in `ExceptionAnalyzer`

Domján Dániel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 12 16:01:34 PST 2023


isuckatcs added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:60
+// Checks if T1 is convertible to T2.
+static bool isMultiLevelConvertiblePointer(QualType P1, QualType P2,
+                                           unsigned CurrentLevel = 0,
----------------
xazax.hun wrote:
> xazax.hun wrote:
> > Did you take a look at `ASTContext::hasCvrSimilarType`? I wonder if it is already doing what you want. 
> Oh, maybe it is not, but it might also make sense to take a look at `ASTContext::typesAreCompatible`.
> Did you take a look at ASTContext::hasCvrSimilarType? I wonder if it is already doing what you want.

This function compares the types by removing the CVR qualifiers.

> Oh, maybe it is not, but it might also make sense to take a look at ASTContext::typesAreCompatible.

This one only compares the canonical types if the language is C++.

```lang=c++
if (getLangOpts().CPlusPlus)
    return hasSameType(LHS, RHS);
----------------------------
bool hasSameType(QualType T1, QualType T2) const {
    return getCanonicalType(T1) == getCanonicalType(T2);
  }

```


================
Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:95
+
+  if (P1->isArrayType() && P2->isArrayType()) {
+    // At every level that array type is involved in, at least
----------------
xazax.hun wrote:
> If none of the functions I recommended works for you, I still strongly suggest reusing utilities from ASTContext, like `UnwrapSimilarTypes` and `UnwrapSimilarArrayTypes`.
I didn't check all of the functions inside `ASTContext`, but here we have very specific rules, we need to check. One utility might help with one check or two, but won't replace the need to go ove all of them. Also I think it's easier to understand which section checks what, if I keep them separated.

In an ealier comment I link to [[ https://en.cppreference.com/w/cpp/language/implicit_conversion#Qualification_conversions | the section on cppreference ]], which discusses what these rules are. Also there I found one controversial example, that's only detected by MSVC. I wonder if you know why that happens.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135495/new/

https://reviews.llvm.org/D135495



More information about the cfe-commits mailing list