dyn_cast vs. dynamic_cast

LLVM has a relatively large number of proprietary replacements for standard C++ functions and classes. One of these is dyn_cast to replace dynamic_cast. The two calls appear to be semantically equivalent; the only difference that I can see is that dyn_cast reportedly works on classes that have no v-table [1]. Could someone please explain why I should use dyn_cast instead of dynamic_cast? (I thought all classes have v-tables...) Thanks,

Trevor

[1] http://llvm.org/docs/ProgrammersManual.html#isa

Trevor Harmon <Trevor.W.Harmon@nasa.gov> writes:

[snip]

Could someone
please explain why I should use dyn_cast instead of dynamic_cast? (I
thought all classes have v-tables...) Thanks,

For reducing executable size, LLVM builds with RTTI disabled where
possible.

dyn_cast is also much much faster than dynamic_cast, which is really important because llvm uses dyn_cast all over the place.

-Chris

Right, but how does that relate to dyn_cast? I thought v-tables were present even when RTTI is not (because otherwise polymorphism would be impossible).

Trevor

dynamic_cast uses rtti, not vtables. dyn_cast doesn't use either, unless you implement the classof method to use it (which is not typical).

-Chris

Trevor Harmon <trevor.w.harmon@nasa.gov> writes:

Could someone
please explain why I should use dyn_cast instead of dynamic_cast? (I
thought all classes have v-tables...) Thanks,

For reducing executable size, LLVM builds with RTTI disabled where
possible.

Right, but how does that relate to dyn_cast? I thought v-tables were
present even when RTTI is not (because otherwise polymorphism would be
impossible).

v-tables are used for dispatching method calls. If you want to know if
something points to certain class (or to a derived class of certain
class) you need RTTI.

This is off-topic here. Googling for RTTI will resolve any remaining
doubts.