<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 - faulty segfault with llvm::TargetMachine"
   href="https://bugs.llvm.org/show_bug.cgi?id=39003">39003</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>faulty segfault with llvm::TargetMachine
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang produces a binary that segfaults for the following code using LLVM
headers:

#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"

#include <string>

int main() {
  llvm::InitializeNativeTarget();

  const char *Triple = "x86_64-unknown-linux-gnu";
  std::string Error;
  auto Target = llvm::TargetRegistry::lookupTarget(Triple, Error);

  if (!Target) return EXIT_FAILURE;

  Target->createTargetMachine(Triple, "generic", "", {}, {}); // SEGFAULT here
}

g++ compiles the code correctly. This code assumes a native triple, but I just
hardcoded it to reduce the test case even further. Calling
TargetRegistry::lookupTarget doesn't change the behavior of clang or gcc.
(here's a link to that version: <a href="https://godbolt.org/z/Bn9rvj">https://godbolt.org/z/Bn9rvj</a>)

I'm using clang r342558 with LLVM r342558 too.

My compiler flags are:

clang++ -O3 test.cpp `llvm-config --ldflags --system-libs --libs all` -o test
-fno-rtti

For g++ I use the exact same flags, just with a 'g++' at the front instead of
'clang++'.</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>