[PATCH] D127434: [clang][dataflow] In `optional` model, match call return via hasType

Sam Estep via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 9 12:41:28 PDT 2022


samestep added a comment.

A test would definitely be good, but I'm not sure how to add one to `UncheckedOptionalAccessModelTest.cpp`, since the issue disappears when we replace `std::unique_ptr` with our custom simple `smart_ptr`. Any ideas?



================
Comment at: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:170
+  // multiple overloads of `hasType` match.
+  ast_matchers::internal::Matcher<Type> typeMatcher = anyOf(
+      optionalOrAliasType(), referenceType(pointee(optionalOrAliasType())));
----------------
ymandel wrote:
> Since we're `using` the `ast_matchers` namespace, no need to qualify. Also, there's a type alias `TypeMatcher` that's not in the internal namespace which would be good here. That said, I'd use `QualType` and write it like this:
> ```
> auto TypeMatcher = qualType(anyOf(...));
> ```
> 
> Or, I think even better in this case, just inline it:
> ```
> callExpr(hasType(anyOf(...)))
> ```
I initially tried inlining it like you suggested, but got a compile error about multiple matching overloads. Adding `qualType` fixed that though, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127434



More information about the cfe-commits mailing list