<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - opt fails with llvm/lib/Transforms/IPO/Inliner.cpp:672: [...] Assertion `IAA->getAdvisor() [...] failed."
   href="https://bugs.llvm.org/show_bug.cgi?id=52118">52118</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>opt fails with llvm/lib/Transforms/IPO/Inliner.cpp:672: [...] Assertion `IAA->getAdvisor() [...] failed.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>janniksilvanus@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25340" name="attach_25340" title="trivial IR example to reproduce">attachment 25340</a> <a href="attachment.cgi?id=25340&action=edit" title="trivial IR example to reproduce">[details]</a></span>
trivial IR example to reproduce

The following opt call crashes on trivial IR input for current main branch as
well as the current release/13.X branch.
12.0 is only affected when using the new pass manager.

opt -S --inline -O1 reduced.ll

Result:

opt:
/home/janniks/software/llvm-project/llvm/lib/Transforms/IPO/Inliner.cpp:672:
llvm::InlineAdvisor& llvm::InlinerPass::getAdvisor(const
llvm::OuterAnalysisManagerProxy<llvm::AnalysisManager<llvm::Module>,
llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>::Result&,
llvm::FunctionAnalysisManager&, llvm::Module&): Assertion `IAA->getAdvisor() &&
"Expected a present InlineAdvisorAnalysis also have an " "InlineAdvisor
initialized"' failed.
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0.      Program arguments:
/home/janniks/software/llvm-project/build-debug/bin/opt -S --inline -O1
reduced.ll
 #0 0x00007f57e9a5742c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
/home/janniks/software/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:22
 #1 0x00007f57e9a574ef PrintStackTraceSignalHandler(void*)
/home/janniks/software/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x00007f57e9a55116 llvm::sys::RunSignalHandlers()
/home/janniks/software/llvm-project/llvm/lib/Support/Signals.cpp:97:20
 #3 0x00007f57e9a56d95 SignalHandler(int)
/home/janniks/software/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007f57eede6870 __restore_rt sigaction.c:0:0
 #5 0x00007f57e92b8d22 raise (/usr/lib/libc.so.6+0x3cd22)
 #6 0x00007f57e92a2862 abort (/usr/lib/libc.so.6+0x26862)
 #7 0x00007f57e92a2747 _nl_load_domain.cold loadmsgcat.c:0:0
 #8 0x00007f57e92b1616 (/usr/lib/libc.so.6+0x35616)
 #9 0x00007f57ed670509
llvm::InlinerPass::getAdvisor(llvm::OuterAnalysisManagerProxy<llvm::AnalysisManager<llvm::Module>,
llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>::Result const&,
llvm::AnalysisManager<llvm::Function>&, llvm::Module&)
/home/janniks/software/llvm-project/llvm/lib/Transforms/IPO/Inliner.cpp:672:3
#10 0x00007f57ed6709a2 llvm::InlinerPass::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
/home/janniks/software/llvm-project/llvm/lib/Transforms/IPO/Inliner.cpp:693:38
#11 0x00007f57eef9201d llvm::detail::PassModel<llvm::LazyCallGraph::SCC,
llvm::InlinerPass, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
/home/janniks/software/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:3
#12 0x00007f57eaa66aba llvm::PassManager<llvm::LazyCallGraph::SCC,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
/home/janniks/software/llvm-project/llvm/lib/Analysis/CGSCCPassManager.cpp:89:39
#13 0x00007f57eef96eb7 llvm::detail::PassModel<llvm::LazyCallGraph::SCC,
llvm::PassManager<llvm::LazyCallGraph::SCC,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
/home/janniks/software/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:3
#14 0x00007f57eaa67626
llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
/home/janniks/software/llvm-project/llvm/lib/Analysis/CGSCCPassManager.cpp:282:48
#15 0x00007f57eef96de1 llvm::detail::PassModel<llvm::Module,
llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
/home/janniks/software/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:3
#16 0x00007f57ea05222d llvm::PassManager<llvm::Module,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
/home/janniks/software/llvm-project/llvm/include/llvm/IR/PassManager.h:525:16
#17 0x0000559265214cf8 llvm::runPassPipeline(llvm::StringRef, llvm::Module&,
llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*,
llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef,
llvm::ArrayRef<llvm::StringRef>, llvm::opt_tool::OutputKind,
llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool)
/home/janniks/software/llvm-project/llvm/tools/opt/NewPMDriver.cpp:489:10
#18 0x000055926524b0d3 main
/home/janniks/software/llvm-project/llvm/tools/opt/opt.cpp:805:27
#19 0x00007f57e92a3b25 __libc_start_main (/usr/lib/libc.so.6+0x27b25)
#20 0x000055926520defe _start
(/home/janniks/software/llvm-project/build-debug/bin/opt+0x1eefe)
zsh: abort (core dumped)  ~/software/llvm-project/build-debug/bin/opt -S
--inline -O1 reduced.ll

It seems the issue is the interplay of two functions pasted at the end.
The assertion fails in the InlinerPass::getAdvisor.

The problem is that IAA is set, but it does not have a set advisor.
This is caused by a previously ran pass of ModuleInlinerWrapperPass as part of
-O1.
In its ModuleInlinerWrapperPass::run function (again cf. end of this post),
we call IAA.clear() which deletes the advisor stored at IAA,
leaving IAA in the state that leads to the assertion fail in
InlineAdvisor::getAdvisor later on.

It would be trivial to "fix" this by checking whether IAA->getAdvisor() is set
in InlinerPass::getAdvisor (instead of only checking IAA),
but I don't know the code and its invariants well enough to decide whether that
is actually
the correct fix or whether ModuleInlinerWrapperPass should not leave the IAA
object in that state.

If that fix above is the right thing, I could implement that change.


InlineAdvisor &
InlinerPass::getAdvisor(const ModuleAnalysisManagerCGSCCProxy::Result &MAM,
                        FunctionAnalysisManager &FAM, Module &M) {
  if (OwnedAdvisor)
    return *OwnedAdvisor;

  auto *IAA = MAM.getCachedResult<InlineAdvisorAnalysis>(M);
  if (!IAA) {
    // It should still be possible to run the inliner as a stand-alone SCC
pass,
    // for test scenarios. In that case, we default to the
    // DefaultInlineAdvisor, which doesn't need to keep state between SCC pass
    // runs. It also uses just the default InlineParams.
    // In this case, we need to use the provided FAM, which is valid for the
    // duration of the inliner pass, and thus the lifetime of the owned
advisor.
    // The one we would get from the MAM can be invalidated as a result of the
    // inliner's activity.
    OwnedAdvisor =
        std::make_unique<DefaultInlineAdvisor>(M, FAM, getInlineParams());

    if (!CGSCCInlineReplayFile.empty())
      OwnedAdvisor = std::make_unique<ReplayInlineAdvisor>(
          M, FAM, M.getContext(), std::move(OwnedAdvisor),
          CGSCCInlineReplayFile,
          /*EmitRemarks=*/true);

    return *OwnedAdvisor;
  }
  assert(IAA->getAdvisor() &&
         "Expected a present InlineAdvisorAnalysis also have an "
         "InlineAdvisor initialized");
  return *IAA->getAdvisor();
}



PreservedAnalyses ModuleInlinerWrapperPass::run(Module &M,
                                                ModuleAnalysisManager &MAM) {
  auto &IAA = MAM.getResult<InlineAdvisorAnalysis>(M);
  if (!IAA.tryCreate(Params, Mode, CGSCCInlineReplayFile)) {
    M.getContext().emitError(
        "Could not setup Inlining Advisor for the requested "
        "mode and/or options");
    return PreservedAnalyses::all();
  }

  // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
  // to detect when we devirtualize indirect calls and iterate the SCC passes
  // in that case to try and catch knock-on inlining or function attrs
  // opportunities. Then we add it to the module pipeline by walking the SCCs
  // in postorder (or bottom-up).
  // If MaxDevirtIterations is 0, we just don't use the devirtualization
  // wrapper.
  if (MaxDevirtIterations == 0)
    MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(PM)));
  else
    MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
        createDevirtSCCRepeatedPass(std::move(PM), MaxDevirtIterations)));
  MPM.run(M, MAM);

  IAA.clear();

  // The ModulePassManager has already taken care of invalidating analyses.
  return PreservedAnalyses::all();
}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>