From fc5370a40de03a6d24ad767928b12dc1381fc643 Mon Sep 17 00:00:00 2001 From: Hong Chen Date: Mon, 1 Apr 2024 10:24:56 -0500 Subject: [PATCH] Incorporate llvm 18 changes. --- CMakeTestFiles/TestICGLinkedLibs.cpp | 5 +++++ .../codegen/Interface_Code_Gen/main.cpp | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CMakeTestFiles/TestICGLinkedLibs.cpp b/CMakeTestFiles/TestICGLinkedLibs.cpp index bb243bcf8..33ce68915 100644 --- a/CMakeTestFiles/TestICGLinkedLibs.cpp +++ b/CMakeTestFiles/TestICGLinkedLibs.cpp @@ -1,4 +1,9 @@ +// `llvm/Support/Host.h` is deprecated in favour of `llvm/TargetParser/Host.h` since clang 17 +#if LIBCLANG_MAJOR > 16 +#include "llvm/TargetParser/Host.h" +#else #include "llvm/Support/Host.h" +#endif #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" diff --git a/trick_source/codegen/Interface_Code_Gen/main.cpp b/trick_source/codegen/Interface_Code_Gen/main.cpp index 0671fbf1a..73cf08d67 100644 --- a/trick_source/codegen/Interface_Code_Gen/main.cpp +++ b/trick_source/codegen/Interface_Code_Gen/main.cpp @@ -6,7 +6,12 @@ #include #include +// `llvm/Support/Host.h` is deprecated in favour of `llvm/TargetParser/Host.h` since clang 17 +#if LIBCLANG_MAJOR > 16 +#include "llvm/TargetParser/Host.h" +#else #include "llvm/Support/Host.h" +#endif #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" @@ -239,8 +244,10 @@ int main(int argc, char * argv[]) { #endif clang::Preprocessor& pp = ci.getPreprocessor(); -#if (LIBCLANG_MAJOR >= 10) +#if (LIBCLANG_MAJOR >= 10) && (LIBCLANG_MAJOR < 18) clang::InitializePreprocessor(pp, ppo, ci.getPCHContainerReader(), ci.getFrontendOpts()); +#else + clang::InitializePreprocessor(pp, ppo, ci.getPCHContainerReader(), ci.getFrontendOpts(), ci.getCodeGenOpts()); #endif // Add all of the include directories to the preprocessor @@ -301,16 +308,20 @@ int main(int argc, char * argv[]) { exit(-1); } // Open up the input file and parse it -#if (LIBCLANG_MAJOR >= 10) +#if (LIBCLANG_MAJOR >= 10 && LIBCLANG_MAJOR < 18) const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath).get(); +#elif (LIBCLANG_MAJOR >= 18) + clang::FileEntryRef fileEntryRef = llvm::cantFail(ci.getFileManager().getFileRef(inputFilePath)); #else const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath); #endif free(inputFilePath); -#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) +#if (LIBCLANG_MAJOR < 3) + ci.getSourceManager().createMainFileID(fileEntry); +#elif (LIBCLANG_MAJOR > 3 && LIBCLANG_MAJOR < 18) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntry, clang::SourceLocation(), clang::SrcMgr::C_User)); #else - ci.getSourceManager().createMainFileID(fileEntry); + ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntryRef, clang::SourceLocation(), clang::SrcMgr::C_User)); #endif ci.getDiagnosticClient().BeginSourceFile(ci.getLangOpts(), &ci.getPreprocessor()); clang::ParseAST(ci.getSema());