[cfe-dev] How to get diagnostics from clang::Parser

Zeke Medley via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 18 10:49:13 PDT 2019


Hi folks,

I'm working on getting incremental processing working with a
CompilerInstance, but am having trouble working out how to handle
syntax errors with any amount of grace.

I'm using the example in
unittests/CodeGen/IncrementalProcessingTest.cpp. If I mess with the
test code in that file and add an error, the parser seems to realize
that, but then the program segfaults in
clang::DiagnosticRenderer::emitDiagnostic according to gdb. The only
thing that I'm changing in the unit test the first test program which
I'm adding a simple error to:

const char TestProgram1[] =
    "extern \"C\" int funcForProg1() { return 17; }\n"
    "struct EmitCXXGlobalInitFunc1 {\n"
    " garbage   EmitCXXGlobalInitFunc1() {}\n"
    "} test1;";

I'm wondering if anyone could help me work out how to capture that
error that the parser is giving. At the very least I'd like some sort
of way to tell that the parser has failed instead of the segfault.

Thanks so much,
Zeke



More information about the cfe-dev mailing list