Get loopinfo in Module Pass

I want to get loopinfo in each function by iterating through functions in Module Pass. My code is as follows:

for (auto &F:M)
{
  if(!F.isDeclaration())
  {
    LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo();
  }
}

However, there is an error, I think my variable Settings should conform to the first function definition, how should I resolve.

clang-12: /llvmtest/llvm/lib/IR/LegacyPassManager.cpp:1645: virtual std::tuple<llvm::Pass*, bool> {anonymous}::MPPassManager::getOnTheFlyPass(llvm::Pass*, llvm::AnalysisID, llvm::Function&): Assertion `FPP && “Unable to find on the fly pass”’ failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.