llvm-redundant-casting

Points out uses of cast<>, dyn_cast<>, isa<> and their or_null variants that are unnecessary because the argument already is of the target type, or a derived type thereof.

struct A {};
A a;
// Finds:
A x = cast<A>(a);
// replaced by:
A x = a;

struct B : public A {};
B b;
// Finds:
A y = cast<A>(b);
// replaced by:
A y = b;

struct C : public A {};
C c;
// Finds:
bool r1 = isa<A>(a)    // always true
bool r2 = isa<A>(b)    // always true
bool r3 = isa<B, C>(c) // always true
Supported functions:
  • llvm::cast

  • llvm::cast_or_null

  • llvm::cast_if_present

  • llvm::dyn_cast

  • llvm::dyn_cast_or_null

  • llvm::dyn_cast_if_present

  • llvm::isa

  • llvm::isa_and_nonnull

  • llvm::isa_and_present