[cfe-dev] getting at the compiler error messages array?

Paul Griffiths gafferuk at gmail.com
Wed Oct 20 04:44:21 PDT 2010


 No matter what I try I can't get at the compiler error messages buffer.

I have tried using code ive found on the net but due to the changing
api, I can't get this to work.

This is what ive got, based on the interpreter example.
Please, someone point me in the right direction.


void LLVMErrorHandler(void *UserData, const std::string &Message)
{
    Diagnostic &Diags = *static_cast<Diagnostic*>(UserData);
    Diags.Report(diag::err_fe_error_backend) << Message;
               :
     // We cannot recover from llvm errors.
     exit(1);
 }






TextDiagnosticBuffer *DiagClient = new TextDiagnosticBuffer();
Diagnostic Diags(DiagClient);
Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
               "a.out", /*IsProduction=*/false, /*CXXIsProduction=*/false,
               Diags);


llvm::llvm_install_error_handler(LLVMErrorHandler,
                            static_cast<void*>(&Clang.getDiagnostics()));



if (!Clang.ExecuteAction(*Act))
{
    TextDiagnosticBuffer::const_iterator    itTextDiagnosticBuffer;
    {
         vector<std::String> vWarnings;
         int iTotalWarnings = 0;
         for (itTextDiagnosticBuffer = DiagClient->warn_begin();
itTextDiagnosticBuffer != DiagClient->warn_end();
++itTextDiagnosticBuffer)
         {
                vWarnings.push_back(itTextDiagnosticBuffer->second.data());
                 iTotalWarnings++;
         }

         char cErrorText[255];
         sprintf (cErrorText, "Total %d warnings!", iTotalWarnings);
       }

       {
             vector<std::String> vErrors;
             int iTotalErrors = 0;
             for (itTextDiagnosticBuffer = DiagClient->err_begin();
itTextDiagnosticBuffer != DiagClient->err_end();
++itTextDiagnosticBuffer)
             {
                     vErrors.push_back(itTextDiagnosticBuffer->second.data());
                      iTotalErrors++;
             }

              char cErrorText[255];
             sprintf (cErrorText, "Total %d errors!", iTotalErrors);
       }
 }



More information about the cfe-dev mailing list