[cfe-dev] ClangTool and -E

Hal Finkel hfinkel at anl.gov
Mon Jan 6 16:00:27 PST 2014


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

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



More information about the cfe-dev mailing list