[cfe-dev] Updating IncrementalProcessingTest.cpp
Zeke Medley via cfe-dev
cfe-dev at lists.llvm.org
Tue Oct 1 22:34:36 PDT 2019
Hi Clang Developers,
I've previously posted on this mailing list about trouble I was having
parsing files with syntax errors using the method used in
IncrementalProcessingTest.cpp. My earlier email is here:
http://clang-developers.42468.n3.nabble.com/How-to-get-diagnostics-from-clang-Parser-td4066041.html
TLDR: At the moment, the way that the incremental processing unit test
shows C++ code being parsed will segfault if the code has any syntax
errors.
I've now figured out how to resolve this issue. The trick is to enter
the source file with the compilers diagnostics client before the
buffer is parse on line 78 and 94.
+ CI.getDiagnosticClient().BeginSourceFile(
CI.getLangOpts(), &CI.getPreprocessor() );
// ... parse the file
+ CI.getDiagnosticClient().EndSourceFile();
Doing this will cause diagnostics to be printed as expected. I think
that it would be appropriate to add this to unit tests that currently
use clang::ParseAST as it might be useful to other people who refers
to those for code examples.
If that sounds appropriate to you all, then I can go ahead and submit
a patch. Otherwise I'd appreciate some input on where it might be
appropriate to add documentation on this as it seems fairly confusing.
I've pasted a diff of a sketch of the changes I'm proposing below.
Thanks,
Zeke
unittests/CodeGen/IncrementalProcessingTest.cpp
79,83d78
< clang::DiagnosticConsumer& DC = CI.getDiagnosticClient();
< DC.clear(); // Clear out any pre existing errors.
<
< DC.BeginSourceFile( CI.getLangOpts(), &CI.getPreprocessor() );
<
99,102d93
<
< DC.EndSourceFile();
< if ( DC.getNumErrors() ) // An error occured parsing the file.
< return nullptr;
More information about the cfe-dev
mailing list