title: LLVM unable to get a required analysis
body: <p>I am writing a pass that needs information about loops. Therefore I am overriding <code>getAnalysisUsage(AnalysisUsage&amp;)</code> to let the pass manager know that my pass depends on <code>LoopInfoWrapperPass</code>. However, when I try to get the result of that analysis, LLVM asserts that the analysis wasn't required by my pass. Here's a simple pass that I'm having trouble with:</p>
  
  <pre><code>#include &lt;llvm/Pass.h&gt;
  #include &lt;llvm/Support/raw_ostream.h&gt;
  #include &lt;llvm/Analysis/LoopInfo.h&gt;
  
  struct Example : public ModulePass {
      static char ID;
      Example() : ModulePass(ID) {}
  
      bool runOnModule(Module&amp; M) override {
          errs() &lt;&lt; "what\n";
          LoopInfo&amp; loops = getAnalysis&lt;LoopInfoWrapperPass&gt;().getLoopInfo();
          loops.print(errs());
  
          return false;
      }
  
      virtual void getAnalysisUsage(AnalysisUsage&amp; AU) const override {
          errs() &lt;&lt; "here\n";
          AU.addRequired&lt;LoopInfoWrapperPass&gt;();
      }
  };
  
  char Example::ID = 0;
  static RegisterPass&lt;Example&gt; X("example", "an example", false, false);
  </code></pre>
  
  <p>When I run this pass, the two debug statements are printed in the correct order (here then what) but when <code>getAnalysis&lt;LoopInfoWrapperPass&gt;()</code> is called, I get this assertion error:</p>
  
  <pre><code>opt: /home/matt/llvm/llvm/include/llvm/PassAnalysisSupport.h:211: AnalysisType&amp; llvm::Pass::getAnalysisID(llvm::AnalysisID) const [with AnalysisType = llvm::LoopInfoWrapperPass; llvm::AnalysisID = const void*]: Assertion `ResultPass &amp;&amp; "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.
  </code></pre>
  
  <p>This is the same method that is given in LLVM's <a href="http://llvm.org/docs/WritingAnLLVMPass.html#specifying-interactions-between-passes" rel="nofollow">documentation on writing passes</a>, so I'm not quite sure what's going wrong here. Could anyone point me in the right direction?</p>