<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Empty error string returned by lto_get_error_message()"
   href="https://llvm.org/bugs/show_bug.cgi?id=26060">26060</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Empty error string returned by lto_get_error_message()
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </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>lto
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>petr.pavlu@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Commit r254721 [1] introduced the following regression:
$ cat test.c
#include <stdio.h>
#include "llvm-c/lto.h"

int main(void)

  lto_module_t m;
  m = lto_module_create("invalid.bc");
  if (m == NULL)
    printf("lto_module_create() failed: %s.\n", lto_get_error_message());
  return 0;
}
$ cc -Illvm/include -Lllvm/build/lib -lLTO test.c
$ touch invalid.bc
$ LD_LIBRARY_PATH=$PWD/llvm/build/lib ./a.out
lto_module_create() failed: .

Previous behaviour:
$ LD_LIBRARY_PATH=$PWD/llvm/build/lib ./a.out
lto_module_create() failed: The file was not recognized as a valid object file.

Previously, tools/lto/lto.cpp:lto_module_create() would pass a sLastErrorString
reference as the ErrMsg parameter to
lib/LTO/LTOModule.cpp:LTOModule::createFromFile() which would pass it further
to lib/LTO/LTOModule.cpp:LTOModule::makeLTOModule() and
lib/LTO/LTOModule.cpp:parseBitcodeFileImpl(). This function would call
lib/Object/IRObjectFile.cpp:IRObjectFile::findBitcodeInMemBuffer() and if it
returned an error it would assign a string representation of it to the received
ErrMsg (aka sLastErrorString).

The commit removed the ErrMsg parameter from these functions and instead
tools/lto/lto.cpp:lto_initialize() registers a diagnostic handler with the
global LLVMContext. The handler then stores any reported errors through this
path to sLastErrorString.

The problem is that
lib/Object/IRObjectFile.cpp:IRObjectFile::findBitcodeInMemBuffer() does not
report errors this way, it only returns object_error::invalid_file_type if the
file is invalid.

[1]
<a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151130/317272.html">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151130/317272.html</a></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>