<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 - OrcJIT's MaterializationResponsibility fails asserts (also in KaleidoscopeJIT Ch2)"
   href="https://bugs.llvm.org/show_bug.cgi?id=41595">41595</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>OrcJIT's MaterializationResponsibility fails asserts (also in KaleidoscopeJIT Ch2)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>8.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>OrcJIT
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>fabian.muehlboeck@outlook.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>1101.debian@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using OrcJIT in llvm 8.0.0 fails very quickly in an assert failure in
MaterializationResponsibility::resolve, which seems to be internal to OrcJIT
and out of the control of the user. Just running Kaleidoscope Ch2 as included
in the source code distribution causes 

    assert(I != SymbolFlags.end() &&
           "Resolving symbol outside this responsibility set");

in lines 399 and 400 of ExecutionEngine/Orc/Core.cpp to fail. In particular,
this seems to reliably happen after entering the second line code, say "5+2"
and "5+2".

Originally, I just tried to compile a function that returns an integer constant
and is marked as having external linkage, which failed in the same function at
lines 407 and 408:

      assert(I->second == KV.second.getFlags() &&
             "Resolving symbol with incorrect flags");

As far as I can tell from the data, "I" has a Flags field whose value is
"Exported | Callable (48 '0')", and "KV" has a Flags field whose value is just
"Callable (32 '0')". After setting up a JIT much like in Kaleidoscope, the
following is all that this code does to produce that error:

auto theModule = llvm::make_unique<llvm::Module>("module", LLVMCONTEXT);
theModule->setDataLayout(NomJIT::Instance()->getDataLayout());

llvm::Function *fun = llvm::Function::Create(llvm::FunctionType::get(INTTYPE,
false), llvm::Function::ExternalLinkage, "testmethod", theModule.get());

BasicBlock *startBlock = BasicBlock::Create(LLVMCONTEXT, "testmethod$start",
fun);

IRBuilder<> builder(LLVMCONTEXT);
builder.SetInsertPoint(startBlock);
builder.CreateRet(llvm::ConstantInt::get(INTTYPE, 5, true));
if (verifyFunction(*fun))
{
        throw "Failed verification";
}

MyJIT::Instance()->addModule(std::move(theModule));
auto MainSymbol = ExitOnErr(MyJIT::Instance()->lookup("testmethod")); //FAILS
HERE
int (*mainmeth)() = (int (*)())(intptr_t)MainSymbol.getAddress();
std::cout<<mainmeth(); 


I'm running Windows 10 and compiled llvm (from the 8.0.0 source tar available
on llvm.org) and the other projects with Visual Studio 2017, and the same
problems happen on two different machines with the same setup.</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>