Thread safety analysis: fix ICE due to missing null check on dyn_cast.