[cfe-dev] ClangTool and -E

Manuel Klimek klimek at google.com
Mon Jan 13 07:40:31 PST 2014


On Tue, Jan 7, 2014 at 1:00 AM, Hal Finkel <hfinkel at anl.gov> wrote:

> Hello,
>
> A colleague of mine gave me some code that used to work (with 3.3), and
> now does not. The core problem seems to be the way it wants to use the
> tooling interface with the preprocessor. Here's a reduced portion (that
> compiles with trunk, but does not work):
>
> #include "clang/Frontend/CompilerInstance.h"
> #include "clang/Frontend/FrontendAction.h"
> #include "clang/Frontend/FrontendActions.h"
> #include "clang/Tooling/CompilationDatabase.h"
> #include "clang/Tooling/CommonOptionsParser.h"
> #include "clang/Tooling/Tooling.h"
>
> using namespace clang::tooling;
> using namespace llvm;
>
> int main()
> {
>   CommonOptionsParser *_optionsParser;
>   const char *argv1[] = { "clang", "/tmp/t.cpp", "--", "-Wall", "-E",  0 };
>   int argc1 = (sizeof argv1) / (sizeof *argv1) - 1;  // do not include
> null at end
>   _optionsParser = new CommonOptionsParser(argc1, argv1,
> cl::GeneralCategory);
>   ClangTool Tool(_optionsParser->getCompilations(),
> _optionsParser->getSourcePathList());
> }
>
> Compiling and running this will produce the error:
> LLVM ERROR: Could not auto-detect compilation database for file
> "/tmp/t.cpp"
> No compilation database found in /tmp or any parent directory
> json-compilation-database: Error while opening JSON database: No such file
> or directory
>

This will not work, as ClangTools don't go through the part of the driver
that handles this, but it should give you a different error message.


> while the equivalent code, compiled against 3.3, did not produce this
> error. If the "-E" is removed from the argv1 array, then the error also
> goes away. Can someone please help me to figure out what is wrong here?
>
> Thanks in advance,
> Hal
>
> --
> Hal Finkel
> Assistant Computational Scientist
> Leadership Computing Facility
> Argonne National Laboratory
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140113/ab171304/attachment.html>


More information about the cfe-dev mailing list