Skip to content

Commit d40bc12

Browse files
authored
Incorporate llvm 18 changes. (#1685)
* 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.
1 parent f475627 commit d40bc12

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

CMakeTestFiles/TestICGLinkedLibs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
// `llvm/Support/Host.h` is deprecated in favour of `llvm/TargetParser/Host.h` since clang 17
2+
#if LIBCLANG_MAJOR > 16
3+
#include "llvm/TargetParser/Host.h"
4+
#else
15
#include "llvm/Support/Host.h"
6+
#endif
27
#include "llvm/Support/CommandLine.h"
38
#include "llvm/Support/raw_ostream.h"
49

trick_source/codegen/Interface_Code_Gen/main.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
#include <sys/stat.h>
77
#include <unistd.h>
88

9+
// `llvm/Support/Host.h` is deprecated in favour of `llvm/TargetParser/Host.h` since clang 17
10+
#if LIBCLANG_MAJOR > 16
11+
#include "llvm/TargetParser/Host.h"
12+
#else
913
#include "llvm/Support/Host.h"
14+
#endif
1015
#include "llvm/Support/CommandLine.h"
1116
#include "llvm/Support/raw_ostream.h"
1217

@@ -239,8 +244,10 @@ int main(int argc, char * argv[]) {
239244
#endif
240245
clang::Preprocessor& pp = ci.getPreprocessor();
241246

242-
#if (LIBCLANG_MAJOR >= 10)
247+
#if (LIBCLANG_MAJOR >= 10) && (LIBCLANG_MAJOR < 18)
243248
clang::InitializePreprocessor(pp, ppo, ci.getPCHContainerReader(), ci.getFrontendOpts());
249+
#elif (LIBCLANG_MAJOR >= 18)
250+
clang::InitializePreprocessor(pp, ppo, ci.getPCHContainerReader(), ci.getFrontendOpts(), ci.getCodeGenOpts());
244251
#endif
245252

246253
// Add all of the include directories to the preprocessor
@@ -301,14 +308,18 @@ int main(int argc, char * argv[]) {
301308
exit(-1);
302309
}
303310
// Open up the input file and parse it
304-
#if (LIBCLANG_MAJOR >= 10)
311+
#if (LIBCLANG_MAJOR >= 10 && LIBCLANG_MAJOR < 18)
305312
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath).get();
313+
#elif (LIBCLANG_MAJOR >= 18)
314+
clang::FileEntryRef fileEntryRef = llvm::cantFail(ci.getFileManager().getFileRef(inputFilePath));
306315
#else
307316
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath);
308317
#endif
309318
free(inputFilePath);
310-
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
319+
#if ((LIBCLANG_MAJOR > 3 && LIBCLANG_MAJOR < 18)) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
311320
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntry, clang::SourceLocation(), clang::SrcMgr::C_User));
321+
#elif (LIBCLANG_MAJOR >= 18)
322+
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntryRef, clang::SourceLocation(), clang::SrcMgr::C_User));
312323
#else
313324
ci.getSourceManager().createMainFileID(fileEntry);
314325
#endif

0 commit comments

Comments
 (0)