Updating IncrementalProcessingTest.cpp

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Updating IncrementalProcessingTest.cpp

Renato Golin via cfe-dev
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;
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev