A problem in Preprocessor::LookupFile

Recently I encountered a problem of “(virtually mapped)header not found” while I was using runToolOnCodeWithArgs for unittesting(I posted this issue to mailing list about three days before. Thank Manuel Klimek for his help).

Today I do a brief tracing on related functions. I suspect there may be a problem in Preprocessor::LookupFile function.


For a virtually mapped header file which is past to runToolOnCodeWithArgs,
its content will be registered to PreprocessorOptions at the end of ToolInvocation::run function(in the Tooling.cpp):

for (const auto &It : MappedFileContents) {
// Inject the code as the given file name into the preprocessor options.
std::unique_ptrllvm::MemoryBuffer Input =

And later, all of the headers are going to be looked up in Preprocessor::LookupFile function(in the PPDirectives.cpp).
I noticed that this function does not look up headers in PreprocessorOptions(member PPOpts in Preprocessor class),
thus therefore any virtually mapped headers cannot be found.

I searched in clang source tree for any spot involves PreprocessorOptions::addRemappedFile.
But I do not see any one include headers in their virtual source code.
So first I want to ask whether it is a good idea to use headers in runToolOnCodeWithArgs?
If it is, is this problem a bug in Preprocessor::LookupFile?

Thank you.