Protect classIsDerivedFrom from run-out-of-stack crash and infinity loop.
Rewrite recursion to loop-over-stack and add checks for complexity to avoid crash on deep definition or infinify recursion.
This fixes https://github.com/llvm/llvm-project/issues/55614
Can you narrow down the check list to just include a check is causing the crash.
Also given we are only ensuring there is no crash, we don't need to invoke FileCheck. clang-tidy will return non-zero if it crashes, causing the whole test to fail.