<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 - llvm::parseIR does not handle extractValue correctly"
   href="https://bugs.llvm.org/show_bug.cgi?id=50092">50092</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm::parseIR does not handle extractValue correctly
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>Bitcode Reader
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>aanderso@tcd.ie
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24796" name="attach_24796" title="minimized test case">attachment 24796</a> <a href="attachment.cgi?id=24796&action=edit" title="minimized test case">[details]</a></span>
minimized test case

I have seen #3465 (<a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - bitcode reader can't handle extractvalue correctly"
   href="show_bug.cgi?id=3465">https://bugs.llvm.org/show_bug.cgi?id=3465</a>) -- this bug is
not that bug.

The attached simple module is handled fine by llvm-as but causes a signal to be
raised when parsed via llvm::parseIR. No parse error message is returned in the
user-supplied char**, we just go straight to throwing an exception. I can't see
a throw in the code in llvm::parseIR so I assume it is coming from deeper in
the machinery.

I am calling llvm::parseIR via LLVMParseIRInContext in the C interface.

It handles many other instructions just fine -- this specific case is the one
breaking. It also handle parse *failures* of other instructions just fine -- we
get an error message describing what went wrong in the user-supplied char**. In
the case of extractValue, we get no error message -- just a crash.

This attached IR fragment is actually from the extractValue description in the
LLVM language reference. If any fragment should parse successfully, I'd think
it should be that one :)

I'm one of the maintainers of the downstream LLVM Haskell bindings
(<a href="https://github.com/llvm-hs/llvm-hs">https://github.com/llvm-hs/llvm-hs</a>), and we have been tracking this problem
since LLVM 3.2 according to one of our commented-out test cases. It would be
great to see a fix so we can test our generation of extractValue instructions
properly.

Any fix can be tested as follows:

Check out llvm-hs from github (you'll have to uncomment the crashing test here:
<a href="https://github.com/llvm-hs/llvm-hs/blob/llvm-9/llvm-hs/test/LLVM/Test/Constants.hs#L158">https://github.com/llvm-hs/llvm-hs/blob/llvm-9/llvm-hs/test/LLVM/Test/Constants.hs#L158</a>)

cd llvm-hs 

LD_LIBRARY_PATH=$(realpath ../llvm-9.0.1-root/lib) PATH=$(realpath
../llvm-9.0.1-root/bin):$PATH stack test

replacing those settings for PATH and LD_LIBRARY_PATH appropriately.</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>