Open PolyProgrammist opened 3 years ago
That's actually spell checking output. file.h is still processed.
However, would be great to consider: 1) Making it a warning instead of error 2) Figure out why this file can't be found the first try and needs further lookup
Extended Description
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
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
include
include
include
int main() { clang::ast_matchers::MatchFinder finder; std::string errMsg; std::shared_ptr 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(*cDb, std::vector({"/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