[llvm-bugs] [Bug 49247] New: Include file not found when file is passed with define option in clang tooling
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Feb 18 05:13:11 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49247
Bug ID: 49247
Summary: Include file not found when file is passed with define
option in clang tooling
Product: clang
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Tooling
Assignee: unassignedclangbugs at nondot.org
Reporter: vad.e.volodin at gmail.com
CC: llvm-bugs at lists.llvm.org
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210218/80988fd2/attachment.html>
More information about the llvm-bugs
mailing list