[cfe-dev] A problem in Preprocessor::LookupFile

Ounan Ding ounanding at gmail.com
Mon Jan 5 07:24:28 PST 2015


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.

Details:

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_ptr<llvm::MemoryBuffer> Input =
        llvm::MemoryBuffer::getMemBuffer(It.getValue());
    Invocation->getPreprocessorOpts().addRemappedFile(It.getKey(),
                                                      Input.release());
  }


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.
--------------------

clang revision: 79f7453146b517c0c1a8cf466399e5bed2e6d83f
Compiler: Visual C++ 2013
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150105/73d1b107/attachment.html>


More information about the cfe-dev mailing list