Skip to content

Commit

Permalink
Incorporate llvm 18 changes. (#1685)
Browse files Browse the repository at this point in the history
* Incorporate llvm 18 changes.

* Fixed to set input file properly for clang3.4 or ealier.

* Fixed missing brackets and added the rule back for the condition to call clang init preprocessor which was taken out incorrectly by the last commit.
  • Loading branch information
hchen99 authored Apr 2, 2024
1 parent f475627 commit d40bc12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeTestFiles/TestICGLinkedLibs.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
17 changes: 14 additions & 3 deletions trick_source/codegen/Interface_Code_Gen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
#include <sys/stat.h>
#include <unistd.h>

// `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"

Expand Down Expand Up @@ -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());
#elif (LIBCLANG_MAJOR >= 18)
clang::InitializePreprocessor(pp, ppo, ci.getPCHContainerReader(), ci.getFrontendOpts(), ci.getCodeGenOpts());
#endif

// Add all of the include directories to the preprocessor
Expand Down Expand Up @@ -301,14 +308,18 @@ 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 && LIBCLANG_MAJOR < 18)) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntry, clang::SourceLocation(), clang::SrcMgr::C_User));
#elif (LIBCLANG_MAJOR >= 18)
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntryRef, clang::SourceLocation(), clang::SrcMgr::C_User));
#else
ci.getSourceManager().createMainFileID(fileEntry);
#endif
Expand Down

0 comments on commit d40bc12

Please sign in to comment.