Skip to content

Commit

Permalink
Merge pull request #78 from ksromanov/patch-1
Browse files Browse the repository at this point in the history
Enable LLVM 15
  • Loading branch information
dbeer1 authored Jun 14, 2023
2 parents 05eeb4d + 1302d31 commit 2c40146
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
8 changes: 8 additions & 0 deletions src/collectors/definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ class DefinitionsDataAppender : public MatchFinder::MatchCallback {

clang::SourceManager *sm = r.SourceManager;
const clang::FileID fid = sm->getFileID(e->getLocation());
#if LLVM_VERSION_MAJOR >= 15
const llvm::Optional<clang::FileEntryRef> 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())) {
return;
}
const types::FileUID fuid = entry->getUID();
#endif

data->defs.insert(
std::pair<types::FileUID, const clang::NamedDecl *>(fuid, e));
Expand Down
16 changes: 16 additions & 0 deletions src/collectors/include_graph/include_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <clang/Lex/Token.h>
#include <clang/Tooling/Core/Replacement.h>
#include <clang/Tooling/Tooling.h>

#include <llvm/ADT/Optional.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/CommandLine.h>

Expand All @@ -53,15 +55,29 @@ 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<clang::FileEntryRef> 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
#if LLVM_VERSION_MAJOR >= 15
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,
imported);
#endif
}

void IncludeFinder::MacroExpands(const clang::Token &macroUsage,
Expand Down
4 changes: 4 additions & 0 deletions src/collectors/include_graph/include_finder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::FileEntryRef> 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;
Expand Down
8 changes: 8 additions & 0 deletions src/collectors/include_graph/include_graph_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ static std::pair<FileUID, bool> 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<FileUID, bool>(0, false);

FileUID fuid = entry->getUID();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/tool_application_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ std::string getExecutablePathFromArgv(const std::string &argv0) {
if (!llvm::sys::path::has_parent_path(exePath)) {
llvm::Optional<std::string> 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) : "";
Expand Down

0 comments on commit 2c40146

Please sign in to comment.