Created attachment 556430 [details] Test program to reproduce the bug I am having an issue with using LLVM's CommandLine library when linking with LLVM. In particular, an extra positional argument is included in the command line from somewhere. Here's how to reproduce it. This program is supposed to take a single argument and print it out. $ cat gentoo-llvm-repro.cpp #include <llvm/Support/CommandLine.h> #include <iostream> llvm::cl::opt<std::string> cl_input(llvm::cl::desc("<actual input file>"), llvm::cl::Positional, llvm::cl::init("-")); int main(int argc, char *argv[]){ llvm::cl::ParseCommandLineOptions(argc, argv); std::cout << cl_input << "\n"; return 0; } $ g++ $(lvm-config --cxxflags --libs --ldflags) gentoo-llvm-repro.cpp Actual: $ ./a.out --help | head -1 USAGE: a.out [options] <input file> <actual input file> $ ./a.out asd - $ ./a.out asd asd asd Expected: $ ./a.out --help | head -1 USAGE: a.out [options] <actual input file> $ ./a.out asd asd $ ./a.out asd asd a.out: Too many positional arguments specified! Can specify at most 1 positional arguments: See: ./a.out -help Affected versions: All I have tried, 4.0.1-r1, 5.0.2, 6.0.1-r2, 7.0.1_rc2, 9999 (from 2018-11-22)
I can confirm that this happens on my system, using =sys-devel/llvm-5.0.1. It happens independently of whether I compile the test program using g++ or clang++, indicating the bug is indeed in llvm (or the gentoo package thereof) and not the compiler used.
I suppose you aren't supposed to link *all* of LLVM libraries like this. If I limit it to 'llvm-config ... support', it works just fine. You may try going through 'llvm-config --components' to see which one breaks it.
It seems to be caused by including the "tablegen" component. However, even with "llvm-config ... support tablegen --ignore-libllvm", I have not been able to reproduce it on any other distribution (I have tried Debian, Ubuntu, FreeBSD-11 (on these, using CommandLine but not linking with libllvm seems to be broken, so clearly linking with all the components is the most common way "in the wild"), and Arch so far), or when building from source.
I spoke too soon about linking with a subset of libraries being broken in Debian, Ubuntu, and FreeBSD. I was able to get that working. However, none of them exhibit the behaviour of Gentoo's LLVM.
Mass-closing bugs reported for removed LLVM versions. Feel free to reopen if the issue still applies and there is no newer report for it.