[all-commits] [llvm/llvm-project] de6ba9: [analyzer][Casting] Support isa, cast, dyn_cast of...

Balazs Benics via All-commits all-commits at lists.llvm.org
Tue Jun 14 04:43:29 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: de6ba9704d0b4fa047a030b5bf369e425b937198
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2022-06-14 (Tue, 14 Jun 2022)

  Changed paths:
    M clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
    M clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp

  Log Message:
  [analyzer][Casting] Support isa, cast, dyn_cast of SVals

This change specializes the LLVM RTTI mechanism for SVals.
After this change, we can use the well-known `isa`, `cast`, `dyn_cast`.


  // SVal V = ...;
  // Loc MyLoc = ...;

  bool IsInteresting = isa<loc::MemRegionVal, loc::GotoLabel>(MyLoc);
  auto MRV = cast<loc::MemRegionVal>(MyLoc);
  Optional<loc::MemRegionVal> MaybeMRV = dyn_cast<loc::MemRegionVal>(V)

The current `SVal::getAs` and `castAs` member functions are redundant at
this point, but I believe that they are still handy.

The member function version is terse and reads left-to-right, which IMO
is a great plus. However, we should probably add a variadic `isa` member
function version to have the same casting API in both cases.

Thanks for the extensive TMP help @bzcheeseman!

Reviewed By: bzcheeseman

Differential Revision: https://reviews.llvm.org/D125709

More information about the All-commits mailing list