[cfe-dev] [bug?] How to use EmitLLVMOnlyAction in clang tool?

Viktor Was BSc via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 30 11:23:26 PDT 2019


I've realized now that the vector is not a Small String equivalent but is a vector of separate char pointers (argv).
Still, for some reason executing an EmitLLVMOnlyAction from a clang tool seems to fail for some reason.

Lldb always exits in CommandLineParser::ParseCommandLineOptions (lib/Support/CommandLine.cpp)
Line 1088 (clang 6.0.1):

'Program Name = sys::path::filename(StringRef(argv[0]));' 

The error... 

'Clang: Not enough positional command line arguments specified!' 

...makes no sense at this particular line.

The only usage of EmitLLVMOnlyAction in the llvm/clang repos seems to be in the clang-interpreter example and for some reason it works there.

Is there some setup missing or present in the ClangTool that screws something up?

gist.github.com/MaliusArth/876db831fca43288bfa6fb78ab6921df

Cheers,
Viktor

On Apr 30, 2019, 03:33, at 03:33, Viktor Was BSc via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>When trying to run an EmitLLVMOnlyAction via
>ClangTool::run(act_factory) I get the following error:
>Clang: Not enough positional command line arguments specified!
>
>Stepping through the code I found that there seems to be a problem in
>setCommandLineOpts in clang/lib/CodeGen/BackendUtils.cpp, the
>BackendArgs.push_back with literals doesn't seem to work and a corrupt
>SmallVector is passed to ParseCommandLineOptions.
>Why is setCommandLineOpts even called, isn't EmitLLVMOnlyAction
>supposed to create llvm::Module in memory only without without
>outputting it to a file? Did I misinterpret the Emit_Nothing flag? What
>does EmitLLVMOnlyAction do?
>What command line args does EmitLLVMOnlyAction expect?
>
>Cmd line: mytool test.cpp -p=compile_commands.json
>
>Compile_commands:
>{
>"directory":"path/to/build",
>"command": "/usr/local/bin/clang++   -Ipath/to/include - std=c++11
>-Wall -o path/to/test.cpp.o -c /path/to/test.cpp",
>"file": "/path/to/test.cpp"
>}
>
>Thanks,
>Viktor
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>cfe-dev mailing list
>cfe-dev at lists.llvm.org
>https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190430/7ef975c6/attachment.html>


More information about the cfe-dev mailing list