clang - LLVM assertion error -


i'm trying use llvm/clang api compile source code llvm ir.

clang_ir.cpp:

#include <iostream>  #include <clang/driver/compilation.h> #include <clang/driver/driver.h> #include <clang/frontend/textdiagnosticprinter.h> #include <llvm/support/host.h> #include <llvm/support/program.h> #include <llvm/support/raw_ostream.h>  using namespace std; using namespace clang; using namespace clang::driver;  int main(int argc, char** argv) {     cout << "starting ----" << std::endl;      // [clang -s -emit-llvm ./test/hello_world.cpp]      // arguments pass clang driver:     string clangpath = "clang";      string inputpath = "./test/hello_world.cpp";     string outputpath = "hello_world.ll";      vector<const char *> args;     args.push_back(clangpath.c_str());     args.push_back("-s");     args.push_back("-emit-llvm");     args.push_back(inputpath.c_str());      // clang driver needs diagnosticsengine can report problems     clang::diagnosticoptions *options = new clang::diagnosticoptions();     //clang::textdiagnosticprinter *diagclient = new clang::textdiagnosticprinter(llvm::errs(), options);     clang::intrusiverefcntptr<clang::diagnosticids> diagid(new clang::diagnosticids());     clang::diagnosticsengine diags(diagid, options);      cout << "making driver" << endl;      // create clang driver     clang::driver::driver thedriver(args[0], llvm::sys::getdefaulttargettriple(), outputpath, diags);      // c++ code     //thedriver.ccciscxx = true;      cout << "making compilation" << endl;      // create set of actions perform     clang::owningptr<clang::driver::compilation> compilation(thedriver.buildcompilation(args));      cout << "printing actions:" << endl;      // print set of actions     thedriver.printactions(*compilation);      std::cout << "done ----" << std::endl;      // carry out actions     int res = 0;     smallvector<std::pair<int, const command *>, 4> failingcommands;     if (compilation)         res = thedriver.executecompilation(*compilation, failingcommands);      // report problems         /*     if (res < 0)         thedriver.generatecompilationdiagnostics(*compilation, failingcommands);         */     (smallvectorimpl< std::pair<int,         const command *> >::iterator = failingcommands.begin(),         ie = failingcommands.end(); != ie; ++it) {             int commandres = it->first;             const command *failingcommand = it->second;             if (!res)               res = commandres;              // if result status < 0, driver command signalled error.             // if result status 70, driver command reported fatal error.             // in these cases, generate additional diagnostic information if possible.             if (commandres < 0 || commandres == 70) {               thedriver.generatecompilationdiagnostics(*compilation, failingcommand);               break;             }       }      return res; } 

successfully built command-line:

mba-anton:build asmirnov$ clang++ llvm-config --cxxflags llvm-config --ldflags llvm-config --libs all -lclang -lclangast -lclangastmatchers -lclanganalysis -lclangapplyreplacements -lclangbasic -lclangcodegen -lclangdriver -lclangdynamicastmatchers -lclangedit -lclangformat -lclangfrontend -lclangfrontendtool -lclangindex -lclanglex -lclangparse -lclangquery -lclangrewritecore -lclangrewritefrontend -lclangsema -lclangserialization -lclangstaticanalyzercheckers -lclangstaticanalyzercore -lclangstaticanalyzerfrontend -lclangtidy -lclangtidyllvmmodule -lclangtooling ../clang_ir.cpp -o clang_ir mba-anton:build asmirnov$

while running i'm getting assertion error:

mba-anton:build asmirnov$ ./clang_ir starting ---- making driver making compilation assertion failed: (getclient() && "diagnosticclient not set!"), function emitcurrentdiagnostic, file /users/asmirnov/documents/dev/src/llvm_34/tools/clang/lib/basic/diagnostic.cpp, line 391. abort trap: 6 mba-anton:build asmirnov$  

what can reason?

it pretty tells problem is. diagnosticclient wasn't set. diagnosticengine requires diagnosticclient- callback when diagnostic occurs.

frankly, clang c++ api full of annoying shit this. it's ask take reference or pointer client in engine constructor. have used fixing each assertion failure comes up.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -