In this lab, we implement an interprocedural sign analysis in both context sensitive and insensitive manner. The source code refer to tutorialpass/pass/InterSignAnalysis

Dynamic cast

The dyn_cast<> operator is a “checking cast” operation. It checks to see if the operand is of the specified type, and if so, returns a pointer to it (this operator does not work with references). If the operand is not of the correct type, a null pointer is returned.

It is defined in include/llvm/Support/Casting.h

template <class X, class Y>
 LLVM_NODISCARD inline std::enable_if_t<
     !is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
 dyn_cast(const Y &Val) {
   return isa<X>(Val) ? cast<X>(Val) : nullptr;
 }

Typically, the dyn_cast<> operator is used in an if statement or some other flow control statement like this. Attention: Val should be the reference type, not pointer type.

if (auto *AI = dyn_cast<AllocationInst>(Val)) {
  // ...
}

The related operators include:

Summary of lab

Reference