Skip to content

Commit

Permalink
Add LLVM 18 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDenisov committed Dec 13, 2024
1 parent c5ab574 commit bceb923
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 15 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/ubuntu_24.04_18/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .devcontainer/ubuntu_24.04_18/devcontainer.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
LLVM_VERSION: [13, 14, 15, 16, 17]
LLVM_VERSION: [13, 14, 15, 16, 17, 18]

steps:
- name: Debugging
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- OS_NAME: "ubuntu"
OS_VERSION: "24.04"
LLVM_VERSION: 17
- OS_NAME: "ubuntu"
OS_VERSION: "24.04"
LLVM_VERSION: 18
name: Ubuntu ${{ matrix.OS_VERSION }} - LLVM ${{ matrix.LLVM_VERSION }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion docs/HowMullWorks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Platform support
----------------

Mull has a great support of macOS and various Linux systems across all modern
versions of LLVM from 11.0 to 15.0. All the new versions of LLVM are supported as
versions of LLVM from 12.0 to 18.0. All the new versions of LLVM are supported as
soon as they released.

Mull is reported to work on Windows Subsystem for Linux, but no official support
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ubuntu": {
"20.04": [12],
"22.04": [13, 14, 15],
"24.04": [14, 15, 16, 17]
"24.04": [14, 15, 16, 17, 18]
}
}

Expand Down
6 changes: 6 additions & 0 deletions infrastructure/helpers/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ SDKROOT: /

llvm_mapping:
macos:
"18":
cmake_search_paths: "/opt/homebrew/opt/llvm@18/lib/cmake/llvm/;/opt/homebrew/opt/llvm@18/lib/cmake/clang/"
packages:
- llvm@18
cmake_cc: /opt/homebrew/opt/llvm@18/bin/clang
cmake_cxx: /opt/homebrew/opt/llvm@18/bin/clang++
"17":
cmake_search_paths: "/opt/homebrew/opt/llvm@17/lib/cmake/llvm/;/opt/homebrew/opt/llvm@17/lib/cmake/clang/"
packages:
Expand Down
9 changes: 9 additions & 0 deletions lib/JunkDetection/CXX/ASTStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ const clang::FileEntry *ThreadSafeASTUnit::findFileEntry(const std::string &file
auto end = sourceManager.fileinfo_end();
const clang::FileEntry *file = nullptr;
for (auto it = begin; it != end; it++) {
#if LLVM_VERSION_MAJOR >= 18
llvm::StringRef currentSourceFilePath = it->first.getFileEntry().getName();
#else
llvm::StringRef currentSourceFilePath = it->first->getName();
#endif

/// In LLVM 6, it->first->getName() does not expand to full path for header files.
if (!llvm::sys::path::is_absolute(currentSourceFilePath)) {
#if LLVM_VERSION_MAJOR >= 18
currentSourceFilePath = it->first.getFileEntry().tryGetRealPathName();
#else
currentSourceFilePath = it->first->tryGetRealPathName();
#endif
}
llvm::SmallString<PATH_MAX> realFilePath;
llvm::sys::fs::real_path(filePath, realFilePath);
Expand Down
12 changes: 11 additions & 1 deletion tests/Helpers/InMemoryCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include <clang/Lex/PreprocessorOptions.h>

#include <llvm/IR/Module.h>
#if LLVM_VERSION_MAJOR >= 18
#include <llvm/TargetParser/Host.h>
#else
#include <llvm/Support/Host.h>
#endif
#include <llvm/Support/TargetSelect.h>

using namespace mull_test;
Expand Down Expand Up @@ -39,10 +43,16 @@ std::unique_ptr<llvm::Module> InMemoryCompiler::compile(const std::string &code,
compilerInvocation, args, clangCompilerInstance.getDiagnostics());
/// Configure options

const auto languageOptions = compilerInvocation.getLangOpts();
auto languageOptions = compilerInvocation.getLangOpts();
#if LLVM_VERSION_MAJOR >= 18
languageOptions.CPlusPlus = 1;
languageOptions.CPlusPlus11 = 1;
languageOptions.Bool = 1;
#else
languageOptions->CPlusPlus = 1;
languageOptions->CPlusPlus11 = 1;
languageOptions->Bool = 1;
#endif

/// auto& preprocessorOptions = compilerInvocation->getPreprocessorOpts();
/// auto& targetOptions = compilerInvocation->getTargetOpts();
Expand Down
14 changes: 7 additions & 7 deletions tools/mull-cxx-frontend/src/ASTInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace cxx {

void ASTInstrumentation::instrumentTranslationUnit() {
/// Create an external getenv() declaration within extern "C" {} block.
clang::LinkageSpecDecl *cLinkageSpecDecl =
clang::LinkageSpecDecl::Create(context,
context.getTranslationUnitDecl(),
NULL_LOCATION,
NULL_LOCATION,
clang::LinkageSpecDecl::LanguageIDs::lang_c,
true);
#if LLVM_VERSION_MAJOR >= 18
auto langID = clang::LinkageSpecLanguageIDs::C;
#else
auto langID = clang::LinkageSpecDecl::LanguageIDs::lang_c;
#endif
clang::LinkageSpecDecl *cLinkageSpecDecl = clang::LinkageSpecDecl::Create(
context, context.getTranslationUnitDecl(), NULL_LOCATION, NULL_LOCATION, langID, true);
getenvFuncDecl = createGetEnvFuncDecl(cLinkageSpecDecl);
cLinkageSpecDecl->addDecl(getenvFuncDecl);
context.getTranslationUnitDecl()->addDecl(cLinkageSpecDecl);
Expand Down
12 changes: 9 additions & 3 deletions tools/mull-cxx-frontend/src/ASTNodeFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ clang::StringLiteral *ASTNodeFactory::createStringLiteral(std::string value) {
return clang::StringLiteral::Create(
context,
value,
#if LLVM_VERSION_MAJOR >= 15
#if LLVM_VERSION_MAJOR >= 18
clang::StringLiteralKind::Ordinary,
#elif LLVM_VERSION_MAJOR >= 15
clang::StringLiteral::StringKind::Ordinary,
#else
clang::StringLiteral::StringKind::Ascii,
Expand Down Expand Up @@ -175,8 +177,12 @@ clang::QualType ASTNodeFactory::getStringLiteralArrayType(clang::QualType type,
}

clang::QualType ASTNodeFactory::getConstantArrayType(clang::QualType type, unsigned size) {
return context.getConstantArrayType(
type, llvm::APInt(8, size + 1), nullptr, clang::ArrayType::ArraySizeModifier::Normal, 0);
#if LLVM_VERSION_MAJOR >= 18
auto sizeModifier = clang::ArraySizeModifier::Normal;
#else
auto sizeModifier = clang::ArrayType::ArraySizeModifier::Normal;
#endif
return context.getConstantArrayType(type, llvm::APInt(8, size + 1), nullptr, sizeModifier, 0);
}

} // namespace cxx
Expand Down
4 changes: 3 additions & 1 deletion tools/mull-cxx-frontend/src/ClangASTMutator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ clang::CallExpr *ClangASTMutator::createGetenvCallExpr(std::string identifier) {
clang::StringLiteral *stringLiteral = clang::StringLiteral::Create(
context,
identifier,
#if LLVM_VERSION_MAJOR >= 15
#if LLVM_VERSION_MAJOR >= 18
clang::StringLiteralKind::Ordinary,
#elif LLVM_VERSION_MAJOR >= 15
clang::StringLiteral::StringKind::Ordinary,
#else
clang::StringLiteral::StringKind::Ascii,
Expand Down

0 comments on commit bceb923

Please sign in to comment.