I have following code to attach textdiagnosticprinter to cling. It results in crash at DiagnosticRenderer::emitDiagnostic. Will appreciate any help to understand what I am doing wrong here.
Thanks
Abhishek
auto compiler = state.interp->getCI();
// get Diagnostics Engine and connect to our diagnostic consumer
auto& de = compiler->getDiagnostics();
auto& langOptions = compiler->getLangOpts() ;
std::string str;
llvm::raw_string_ostream os(str);
clang::DiagnosticOptions &diagnosticOptions =compiler->getDiagnosticOpts();
clang::TextDiagnosticPrinter *pTextDiagnosticPrinter =
new clang::TextDiagnosticPrinter(os, &diagnosticOptions, true);
de.setClient(pTextDiagnosticPrinter, true);
(lldb) bt
- thread #1, queue = ‘com.apple.main-thread’, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
- frame #0: 0x000000010039c91c cling-cli
clang::DiagnosticRenderer::emitDiagnostic(clang::FullSourceLoc, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRef<clang::CharSourceRange>, llvm::ArrayRef<clang::FixItHint>, llvm::PointerUnion<clang::Diagnostic const*, clang::StoredDiagnostic const*>) + 76 frame #1: 0x00000001003e1513 cling-cli
clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) + 1331
frame #2: 0x00000001024ffd5e cling-cliclang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const + 382 frame #3: 0x00000001024f97e9 cling-cli
clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) + 89
- frame #0: 0x000000010039c91c cling-cli