[llvm-bugs] [Bug 39003] New: faulty segfault with llvm::TargetMachine

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 19 11:27:44 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39003

            Bug ID: 39003
           Summary: faulty segfault with llvm::TargetMachine
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: blitzrakete at gmail.com
                CC: llvm-bugs at lists.llvm.org

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: https://godbolt.org/z/Bn9rvj)

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++'.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180919/166021e4/attachment.html>


More information about the llvm-bugs mailing list