<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Include file not found when file is passed with define option in clang tooling"
   href="https://bugs.llvm.org/show_bug.cgi?id=49247">49247</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Include file not found when file is passed with define option in clang tooling
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Tooling
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vad.e.volodin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang tooling says that include file not found, however running command in
terminal gives positive result.

file.c:
#include "stdio.h"
#include THE_INCLUDE

int main() {
        printf("%d\n", f(5));
}

file.h:
int f(int a) {
        return a + 1;
}

compile_commands.json:
[
    {
        "arguments": [
            "clang",
            "-c",
            "-o",
            "file.o",
            "-DTHE_INCLUDE=\"\\\"file.h\\\"\"",
            "file.c"
        ],
        "directory": "/home/utbot/work/tmp",
        "file": "file.c"
    }
]

Output of clang tooling:
clang -c -o file.o -DTHE_INCLUDE="\"file.h\"" file.c 
file.c:3:10: error: '\"file.h\"' file not found, did you mean 'file.h'?
#include THE_INCLUDE
         ^
<command line>:1:21: note: expanded from here
#define THE_INCLUDE "\"file.h\""
                    ^
1 error generated.
Error while processing /home/utbot/work/tmp/file.c.

Note that this command runs ok in terminal:
clang -c -o file.o -DTHE_INCLUDE="\"file.h\"" file.c 

Also tooling code:
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/Tooling/CommonOptionsParser.h>
#include <clang/Tooling/Tooling.h>

#include <string>
#include <vector>
#include <memory>
#include <iostream>

int main() {
    clang::ast_matchers::MatchFinder finder;
    std::string errMsg;
    std::shared_ptr<clang::tooling::CompilationDatabase> cDb =
clang::tooling::CompilationDatabase::autoDetectFromDirectory("/home/utbot/work/tmp",
errMsg);
    std::cout << errMsg; // No output
    for (auto command: cDb->getAllCompileCommands()) {
        for (auto option: command.CommandLine) {
            std::cout << option << ' ';
        }
        std::cout << std::endl;
    }
    auto clangTool = std::make_unique<clang::tooling::ClangTool>(*cDb,
std::vector<std::string>({"/home/utbot/work/tmp/file.c"}));
    clangTool->run(clang::tooling::newFrontendActionFactory(&finder).get());
}

cmake for tooling code:
cmake_minimum_required(VERSION 3.16)
project(untitled)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -fstandalone-debug
-fno-discard-value-names -fno-elide-constructors")


find_package(Clang REQUIRED)
include_directories(${CLANG_INCLUDE_DIRS})
add_definitions(${CLANG_DEFINITIONS})

add_executable(clang_error main.cpp)
target_link_libraries(clang_error PUBLIC clangTooling clangBasic
clangASTMatchers)


Using clang 10.0.0</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>