On-the-fly passes

I'm seeing some very unexpected behavior in a ModulePass I've created.
To support both the legacy and new pass managers, I've abstracted away
the code to get the passes it depends on:

bool MyPass::runOnModule(Module &M) override {
  auto DominatorGetter = [this] (Function &F) -> DominatorTree & {
    return this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();

      auto PostDominatorGetter = [this] (Function &F) -> PostDominatorTree & {
        return this->

      auto LoopInfoGetter = [this] (Function &F) -> LoopInfo & {
        return this->getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo();

      auto SCEVGetter = [this] (Function &F) -> ScalarEvolution & {
        return this->getAnalysis<ScalarEvolutionWrapperPass>(F).getSE();

      auto AssumptionCacheGetter = [this] (Function &F) ->
        AssumptionCache & {

      auto OREGetter = [this] (Function &F) -> OptimizationRemarkEmitter & {
        return this->

What is the behavior that you are not expecting?


Philip Pfaffe via llvm-dev <llvm-dev@lists.llvm.org> writes:

What is the behavior that you are not expecting?

Sorry, I hit send too quickly. I posted a later message with all the