<div dir="ltr">LGTM</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 7, 2014 at 1:33 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Added unit test.<br>
<br>
<a href="http://reviews.llvm.org/D4773" target="_blank">http://reviews.llvm.org/D4773</a><br>
<br>
Files:<br>
lib/Frontend/FrontendAction.cpp<br>
unittests/Frontend/FrontendActionTest.cpp<br>
<div class=""><br>
Index: lib/Frontend/FrontendAction.cpp<br>
===================================================================<br>
--- lib/Frontend/FrontendAction.cpp<br>
+++ lib/Frontend/FrontendAction.cpp<br>
@@ -432,6 +432,10 @@<br>
// Inform the diagnostic client we are done with this source file.<br>
CI.getDiagnosticClient().EndSourceFile();<br>
<br>
+ // Inform the preprocessor we are done.<br>
+ if (CI.hasPreprocessor())<br>
+ CI.getPreprocessor().EndSourceFile();<br>
+<br>
// Finalize the action.<br>
EndSourceFileAction();<br>
<br>
@@ -453,10 +457,6 @@<br>
CI.setASTConsumer(nullptr);<br>
}<br>
<br>
- // Inform the preprocessor we are done.<br>
- if (CI.hasPreprocessor())<br>
- CI.getPreprocessor().EndSourceFile();<br>
-<br>
if (CI.getFrontendOpts().ShowStats) {<br>
llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n";<br>
CI.getPreprocessor().PrintStats();<br>
</div>Index: unittests/Frontend/FrontendActionTest.cpp<br>
===================================================================<br>
--- unittests/Frontend/FrontendActionTest.cpp<br>
+++ unittests/Frontend/FrontendActionTest.cpp<br>
@@ -100,4 +100,50 @@<br>
EXPECT_EQ("x", test_action.decl_names[1]);<br>
}<br>
<br>
+struct TestPPCallbacks : public PPCallbacks {<br>
+ TestPPCallbacks() : SeenEnd(false) {}<br>
+<br>
+ void EndOfMainFile() override { SeenEnd = true; }<br>
+<br>
+ bool SeenEnd;<br>
+};<br>
+<br>
+class TestPPCallbacksFrontendAction : public PreprocessorFrontendAction {<br>
+ TestPPCallbacks *Callbacks;<br>
+<br>
+public:<br>
+ TestPPCallbacksFrontendAction(TestPPCallbacks *C)<br>
+ : Callbacks(C), SeenEnd(false) {}<br>
+<br>
+ void ExecuteAction() override {<br>
+ Preprocessor &PP = getCompilerInstance().getPreprocessor();<br>
+ PP.addPPCallbacks(Callbacks);<br>
+ PP.EnterMainSourceFile();<br>
+ }<br>
+ void EndSourceFileAction() override { SeenEnd = Callbacks->SeenEnd; }<br>
+<br>
+ bool SeenEnd;<br>
+};<br>
+<br>
+TEST(PreprocessorFrontendAction, EndSourceFile) {<br>
+ CompilerInvocation *Invocation = new CompilerInvocation;<br>
+ Invocation->getPreprocessorOpts().addRemappedFile(<br>
+ "test.cc", MemoryBuffer::getMemBuffer("int main() { float x; }"));<br>
+ Invocation->getFrontendOpts().Inputs.push_back(<br>
+ FrontendInputFile("test.cc", IK_CXX));<br>
+ Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly;<br>
+ Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";<br>
+ CompilerInstance Compiler;<br>
+ Compiler.setInvocation(Invocation);<br>
+ Compiler.createDiagnostics();<br>
+<br>
+ TestPPCallbacks *Callbacks = new TestPPCallbacks;<br>
+ TestPPCallbacksFrontendAction TestAction(Callbacks);<br>
+ ASSERT_FALSE(Callbacks->SeenEnd);<br>
+ ASSERT_FALSE(TestAction.SeenEnd);<br>
+ ASSERT_TRUE(Compiler.ExecuteAction(TestAction));<br>
+ // Check that EndOfMainFile was called before EndSourceFileAction.<br>
+ ASSERT_TRUE(TestAction.SeenEnd);<br>
+}<br>
+<br>
} // anonymous namespace<br>
</blockquote></div><br></div>