[PATCH] D59802: [clang-tidy] Add new checker: llvm-avoid-cast-in-conditional

Don Hinton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 26 13:07:32 PDT 2019


hintonda added a comment.

In D59802#1443451 <https://reviews.llvm.org/D59802#1443451>, @hintonda wrote:

> In D59802#1443340 <https://reviews.llvm.org/D59802#1443340>, @aaron.ballman wrote:
>
> > Should this check also try to find this pattern:
> >
> >   if (dyn_cast<Frobble>(Bobble))
> >     ...
> >
> >
> > in order to recommend the proper replacement:
> >
> >   if (isa<Frobble>(Bobble))
> >     ...
> >
> >
> > I ask because the name `llvm-avoid-cast-in-conditional` sounds like it would also cover this situation and I run into it during code reviews with some frequency (more often than I run into `cast<>` being used in a conditional).
>
>
> Yes, I can add that, and provide a fix-it too.  Thanks...


I did a quick grep and found a few of these, but also found the `_or_null<>` variety.  Guess they'll need to stay the same since `isa<>` can't handle nulls.

Btw, I also found the same pattern used for `while()`, so I'll add that too.  Here's a sample of the patterns I'm seeing:

./lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp:213:  while (dyn_cast<NullStmt>(last_stmt)) {
./clang/lib/CodeGen/CodeGenModule.cpp:1390:  if (dyn_cast_or_null<NamedDecl>(D)) .     // <--- this one's okay
./clang/lib/CodeGen/CodeGenModule.cpp:3950:    if (dyn_cast<llvm::CallInst>(callSite)) {


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59802





More information about the cfe-commits mailing list