From ed6cef3e760350d8acd8408ae34272c1fb68656a Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Mon, 12 Jun 2023 18:12:55 -0400 Subject: [PATCH 1/3] Enable LLVM 15 Signed-off-by: Konstantin Romanov --- .travis.yml | 6 ++++++ src/collectors/definitions.cpp | 4 ++++ src/collectors/include_graph/include_finder.cpp | 11 +++++++++++ src/collectors/include_graph/include_finder.h | 4 ++++ src/collectors/include_graph/include_graph_util.cpp | 8 ++++++++ src/tool_application_support.cpp | 4 ++++ 6 files changed, 37 insertions(+) diff --git a/.travis.yml b/.travis.yml index 40e5b89..40f25c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,3 +30,9 @@ matrix: language: cpp sudo: true script: docker build --build-arg TARGET_LLVM_VERSION=14 --build-arg BASE_IMAGE=ubuntu:22.04 --build-arg GCC_VERSION=9 --build-arg IMAGE_REPO=jammy . + - os: linux + dist: jammy + compiler: gcc + language: cpp + sudo: true + script: docker build --build-arg TARGET_LLVM_VERSION=15 --build-arg BASE_IMAGE=ubuntu:22.04 --build-arg GCC_VERSION=9 --build-arg IMAGE_REPO=jammy . diff --git a/src/collectors/definitions.cpp b/src/collectors/definitions.cpp index 250c753..5dfb45a 100644 --- a/src/collectors/definitions.cpp +++ b/src/collectors/definitions.cpp @@ -26,7 +26,11 @@ class DefinitionsDataAppender : public MatchFinder::MatchCallback { clang::SourceManager *sm = r.SourceManager; const clang::FileID fid = sm->getFileID(e->getLocation()); const clang::FileEntry *entry = sm->getFileEntryForID(fid); +#if LLVM_VERSION_MAJOR >= 15 + if (!entry) { +#else if (!(entry && entry->isValid())) { +#endif return; } const types::FileUID fuid = entry->getUID(); diff --git a/src/collectors/include_graph/include_finder.cpp b/src/collectors/include_graph/include_finder.cpp index 98ee85d..7f89530 100644 --- a/src/collectors/include_graph/include_finder.cpp +++ b/src/collectors/include_graph/include_finder.cpp @@ -35,6 +35,8 @@ #include #include #include + +#include #include #include @@ -53,14 +55,23 @@ using clangmetatool::types::MacroReferenceInfo; void IncludeFinder::InclusionDirective( clang::SourceLocation hashLoc, const clang::Token &includeToken, llvm::StringRef filename, bool isAngled, +#if LLVM_VERSION_MAJOR >= 15 + clang::CharSourceRange filenameRange, llvm::Optional file, +#else clang::CharSourceRange filenameRange, const clang::FileEntry *file, +#endif llvm::StringRef searchPath, llvm::StringRef relativePath, const clang::Module *imported, clang::SrcMgr::CharacteristicKind FileType_) { // The filetype characteristic is unused for now, hence marked with // a trailing '_'. We are recording all filetypes add_include_statement(ci, data, hashLoc, includeToken, filename, isAngled, +#if LLVM_VERSION_MAJOR >= 15 + filenameRange, file.has_value() ? &file.value().getFileEntry() : nullptr, + searchPath, relativePath, +#else filenameRange, file, searchPath, relativePath, +#endif imported); } diff --git a/src/collectors/include_graph/include_finder.h b/src/collectors/include_graph/include_finder.h index da9699d..2fd157d 100644 --- a/src/collectors/include_graph/include_finder.h +++ b/src/collectors/include_graph/include_finder.h @@ -35,7 +35,11 @@ class IncludeFinder : public clang::PPCallbacks { InclusionDirective(clang::SourceLocation hashLoc, const clang::Token &includeToken, llvm::StringRef filename, bool isAngled, clang::CharSourceRange filenameRange, +#if LLVM_VERSION_MAJOR >= 15 + llvm::Optional File, llvm::StringRef SearchPath, +#else const clang::FileEntry *file, llvm::StringRef searchPath, +#endif llvm::StringRef relativePath, const clang::Module *imported, clang::SrcMgr::CharacteristicKind FileType_) override; diff --git a/src/collectors/include_graph/include_graph_util.cpp b/src/collectors/include_graph/include_graph_util.cpp index 937871c..a1159f2 100644 --- a/src/collectors/include_graph/include_graph_util.cpp +++ b/src/collectors/include_graph/include_graph_util.cpp @@ -58,7 +58,11 @@ static std::pair get_fileuid(clang::CompilerInstance *ci, clang::SourceManager &sm = ci->getSourceManager(); const clang::FileEntry *entry = sm.getFileEntryForID(fid); +#if LLVM_VERSION_MAJOR >= 15 + if (!entry) +#else if (!(entry && entry->isValid())) +#endif return std::pair(0, false); FileUID fuid = entry->getUID(); @@ -101,7 +105,11 @@ void add_include_statement(clang::CompilerInstance *ci, IncludeGraphData *data, const clang::Module *imported) { std::string include = (std::string)relativePath; +#if LLVM_VERSION_MAJOR >= 15 + if (file) { +#else if (file && file->isValid()) { +#endif FileUID fuid = file->getUID(); data->fuid2entry.emplace(fuid, file); diff --git a/src/tool_application_support.cpp b/src/tool_application_support.cpp index 7a92ab0..57b4595 100644 --- a/src/tool_application_support.cpp +++ b/src/tool_application_support.cpp @@ -47,7 +47,11 @@ std::string getExecutablePathFromArgv(const std::string &argv0) { if (!llvm::sys::path::has_parent_path(exePath)) { llvm::Optional maybeExePath = llvm::sys::Process::FindInEnvPath("PATH", argv0); +#if LLVM_VERSION_MAJOR >= 15 + exePath = maybeExePath.value_or(""); +#else exePath = maybeExePath.getValueOr(""); +#endif } } return !exePath.empty() ? getRealpath(exePath) : ""; From 22b23b6c2bd22e7fb037eab48f884f424ef26d03 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Tue, 13 Jun 2023 16:56:20 -0400 Subject: [PATCH 2/3] Do not call add_include_statement if file is nullptr Signed-off-by: Konstantin Romanov --- src/collectors/include_graph/include_finder.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/collectors/include_graph/include_finder.cpp b/src/collectors/include_graph/include_finder.cpp index 7f89530..2717583 100644 --- a/src/collectors/include_graph/include_finder.cpp +++ b/src/collectors/include_graph/include_finder.cpp @@ -63,16 +63,21 @@ void IncludeFinder::InclusionDirective( llvm::StringRef searchPath, llvm::StringRef relativePath, const clang::Module *imported, clang::SrcMgr::CharacteristicKind FileType_) { + // The filetype characteristic is unused for now, hence marked with // a trailing '_'. We are recording all filetypes - add_include_statement(ci, data, hashLoc, includeToken, filename, isAngled, #if LLVM_VERSION_MAJOR >= 15 - filenameRange, file.has_value() ? &file.value().getFileEntry() : nullptr, - searchPath, relativePath, + if(file.has_value()) { + add_include_statement(ci, data, hashLoc, includeToken, filename, isAngled, + filenameRange, &file.value().getFileEntry(), + searchPath, relativePath, + imported); + } #else + add_include_statement(ci, data, hashLoc, includeToken, filename, isAngled, filenameRange, file, searchPath, relativePath, -#endif imported); +#endif } void IncludeFinder::MacroExpands(const clang::Token ¯oUsage, From 1302d312b2a52b3bcb733fbca3026801b34bcaa9 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Tue, 13 Jun 2023 18:05:01 -0400 Subject: [PATCH 3/3] Use getFileEntryRefForID for llvm 15. Signed-off-by: Konstantin Romanov --- src/collectors/definitions.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/collectors/definitions.cpp b/src/collectors/definitions.cpp index 5dfb45a..a651e5f 100644 --- a/src/collectors/definitions.cpp +++ b/src/collectors/definitions.cpp @@ -25,15 +25,19 @@ class DefinitionsDataAppender : public MatchFinder::MatchCallback { clang::SourceManager *sm = r.SourceManager; const clang::FileID fid = sm->getFileID(e->getLocation()); - const clang::FileEntry *entry = sm->getFileEntryForID(fid); #if LLVM_VERSION_MAJOR >= 15 - if (!entry) { + const llvm::Optional entry = sm->getFileEntryRefForID(fid); + if (!entry.has_value()) { + return; + } + const types::FileUID fuid = entry.value().getUID(); #else + const clang::FileEntry *entry = sm->getFileEntryForID(fid); if (!(entry && entry->isValid())) { -#endif return; } const types::FileUID fuid = entry->getUID(); +#endif data->defs.insert( std::pair(fuid, e));